Link Prompts and Experiments when prompts are loaded/registered#18883
Link Prompts and Experiments when prompts are loaded/registered#18883TomeHirata merged 11 commits intomlflow:masterfrom
Conversation
- Introduced functionality to link prompt versions to experiments, allowing for better organization and tracking of prompts within specific experiments. - Updated the `AbstractStore` and its SQLAlchemy implementation to include methods for adding and retrieving prompt-experiment associations. - Enhanced the `MlflowClient` to facilitate linking prompts during registration and loading processes. - Added tests to ensure correct linking behavior and to verify that prompts can be associated with multiple experiments without duplication. Signed-off-by: Tomu Hirata <tomu.hirata@gmail.com>
- Updated the prompt linking mechanism to tag prompts with associated experiment IDs instead of creating entity associations. - Modified the `AbstractStore` and its SQLAlchemy implementation to remove methods related to prompt-experiment associations. - Enhanced the `MlflowClient` to manage experiment ID tags during prompt registration and loading. - Updated tests to verify the new tagging behavior and ensure idempotency when tagging prompts with the same experiment ID. Signed-off-by: Tomu Hirata <tomu.hirata@gmail.com>
…tore class Signed-off-by: Tomu Hirata <tomu.hirata@gmail.com>
…es and update search_prompts function to return a list instead of PagedList. Enhance docstring for clarity on prompt search functionality. Signed-off-by: Tomu Hirata <tomu.hirata@gmail.com>
There was a problem hiding this comment.
Pull Request Overview
This PR adds the ability to link prompts to experiments when prompts are loaded or registered within an active MLflow run. Experiment IDs are stored as comma-separated values in a special prompt tag, enabling users to search for prompts by experiment.
- Tracks experiment linkage via
PROMPT_EXPERIMENT_IDS_TAG_KEYtag whenload_promptorregister_promptis called within an active run - Implements
experiment_idfilter syntax forsearch_prompts()API that translates to tag-based filtering - Adds integration tests covering prompt-experiment linking and search functionality
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/genai/prompts/test_prompts.py | Adds comprehensive integration tests for prompt-experiment linking and searching by experiment ID |
| mlflow/tracking/client.py | Updates register_prompt to link prompts to experiments and enhances search_prompts documentation with experiment_id filter examples |
| mlflow/tracking/_model_registry/fluent.py | Updates load_prompt to link prompts to experiments, improves search_prompts documentation, and fixes deprecated _logger.warn usage |
| mlflow/store/model_registry/abstract_store.py | Implements _parse_experiment_id_filter to transform experiment_id filter syntax to tag-based LIKE queries |
| mlflow/store/_unity_catalog/registry/rest_store.py | Integrates _parse_experiment_id_filter into Unity Catalog search_prompts implementation |
| mlflow/prompt/constants.py | Adds PROMPT_EXPERIMENT_IDS_TAG_KEY constant for storing experiment IDs in prompt tags |
| mlflow/entities/entity_type.py | Adds PROMPT entity association type for consistency |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Updated the prompt linking mechanism to ensure prompts are tagged with associated experiment IDs during registration and loading. - Refactored the `MlflowClient` to manage experiment ID tags more effectively, including asynchronous handling for linking prompts to experiments. - Improved SQL injection protection in the `AbstractStore` by escaping backslashes in experiment IDs. - Updated tests to verify the new tagging behavior and ensure correct linking of prompts to experiments without duplication. Signed-off-by: Tomu Hirata <tomu.hirata@gmail.com>
|
Documentation preview for c1d4e23 is available at: More info
|
mlflow/tracking/client.py
Outdated
| # Use LIKE to match the experiment ID and experiment ID is auto-incremented | ||
| # integer. So add comma before and after the list of experiment IDs to | ||
| # avoid false matches (e.g., "1" matches "10"). | ||
| exp_ids = f",{exp_ids}," |
There was a problem hiding this comment.
This is not very beautiful, but I couldn't think of a better way to store and query a list type field without changing the schema of RegisteredModel. EntityAssociation is not really applicable for Prompts since it's managed by model registry store while EntityAssociation is in tracking store.
There was a problem hiding this comment.
Makes sense, I think it is inevitable. Can we make sure this update is thread-safe and does not affect performance (I guess so cuz we file is async, but we should make sure no memory leak).
There was a problem hiding this comment.
Sounds good, added a lock and moved the linkage logic so that it's called only when there's cache miss.
mlflow/tracking/client.py
Outdated
| # Use LIKE to match the experiment ID and experiment ID is auto-incremented | ||
| # integer. So add comma before and after the list of experiment IDs to | ||
| # avoid false matches (e.g., "1" matches "10"). | ||
| exp_ids = f",{exp_ids}," |
There was a problem hiding this comment.
Makes sense, I think it is inevitable. Can we make sure this update is thread-safe and does not affect performance (I guess so cuz we file is async, but we should make sure no memory leak).
|
/review check type hints and general coding standard ✅ Review completed. Review OutputPerfect! I've completed the PR review and added comments for all the issues I found. Let me summarize what I found: PR Review SummaryI reviewed PR #18883 "Link Prompts and Experiments when prompts are loaded/registered" and found 3 issues that should be addressed: Issues Found:
All comments have been posted to the PR with specific suggestions for fixes. |
… to experiments. Added a fixture to ensure linkage threads complete in tests. Signed-off-by: Tomu Hirata <tomu.hirata@gmail.com>
Signed-off-by: TomuHirata <tomu.hirata@gmail.com>
|
The failures are related to the conda issue. |
…ow#18883) Signed-off-by: Tomu Hirata <tomu.hirata@gmail.com> Signed-off-by: TomuHirata <tomu.hirata@gmail.com>
Signed-off-by: Tomu Hirata <tomu.hirata@gmail.com> Signed-off-by: TomuHirata <tomu.hirata@gmail.com>
🛠 DevTools 🛠
Install mlflow from this PR
For Databricks, use the following command:
Related Issues/PRs
n/a
What changes are proposed in this pull request?
Currently linkage to prompt version is tracked for runs, spans, and logged models. In order to allow users to group prompts by experiments, we want to track the linkage between experiments and prompts.
Changes:
How is this PR tested?
Does this PR require documentation update?
Release Notes
Is this a user-facing change?
What component(s), interfaces, languages, and integrations does this PR affect?
Components
area/tracking: Tracking Service, tracking client APIs, autologgingarea/models: MLmodel format, model serialization/deserialization, flavorsarea/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registryarea/scoring: MLflow Model server, model deployment tools, Spark UDFsarea/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflowsarea/gateway: MLflow AI Gateway client APIs, server, and third-party integrationsarea/prompts: MLflow prompt engineering features, prompt templates, and prompt managementarea/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionalityarea/projects: MLproject format, project running backendsarea/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev serverarea/build: Build and test infrastructure for MLflowarea/docs: MLflow documentation pagesHow should the PR be classified in the release notes? Choose one:
rn/none- No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" sectionrn/breaking-change- The PR will be mentioned in the "Breaking Changes" sectionrn/feature- A new user-facing feature worth mentioning in the release notesrn/bug-fix- A user-facing bug fix worth mentioning in the release notesrn/documentation- A user-facing documentation change worth mentioning in the release notesShould this PR be included in the next patch release?
Yesshould be selected for bug fixes, documentation updates, and other small changes.Noshould be selected for new features and larger changes. If you're unsure about the release classification of this PR, leave this unchecked to let the maintainers decide.What is a minor/patch release?
Bug fixes, doc updates and new features usually go into minor releases.
Bug fixes and doc updates usually go into patch releases.