CertSafari
    Databricks Certified Generative AI Engineer Associate· Lessons

    Domain 3 · Lesson 24/56

    Selecting the best model from MLflow experiment metrics

    Select the best model for a given task based on common metrics generated in experiments

    17 min read
    2.31% of exam
    10 sources
    Published 22 Oct 2026
    Docs as of 17 Oct 2026

    What you will be able to do

    • Say which evaluation metrics need ground-truth expected answers and which can score outputs without them
    • Compare candidate models by changing only the model and keeping the same evaluation dataset and judges, then read the side-by-side comparison for gains and regressions
    • Separate pass/fail constraints such as safety and latency from the metric that actually decides between candidates
    • Filter, chart and rank runs and Logged Models on a primary metric, then promote the winner toward Unity Catalog
    • Check an embedding model's documented maximum token limit against your largest chunk before comparing benchmark scores

    Key concept

    Controlled comparison on a deciding metric — Score each candidate model on the same evaluation dataset with the same judges, so the model is the only thing that changes between runs. Then drop any candidate that fails a hard requirement, and pick among the rest using the one metric that still separates them.

    1.What the metrics in an experiment measure

    You pick a model by reading numbers out of an MLflow experiment, so start by knowing what each number measures. Every run is one execution of model code. It records parameters, metrics, tags and artifacts, and an experiment groups related runs so you can compare and filter them. For a generative AI application, Databricks groups the useful metrics into three dimensions: quality (of retrieval and of the response), cost (token counts) and latency (how long the app takes to run).

    The dimensions differ in how they are measured. Cost and latency are computed deterministically from what the app outputs: total_token_count is a count and latency_seconds is a timing, so no judgement is involved. Most quality metrics come from an LLM judge, which is a separate model that reads the request and the response and scores them. Judges themselves come in two kinds, and the difference decides what your evaluation dataset has to contain.

    Reference-based judges compare the app's output with a human-labelled expected answer. Correctness is the standard example: it asks whether the response is correct compared with the ground truth, so every row it scores needs that expectation. Reference-free judges look only at the request, the response and any retrieved context. Safety asks whether the content is free from harmful, offensive or toxic material. Groundedness asks whether the response is supported by the retrieved context. Relevance asks whether the response addresses the request. None of these three needs an expected answer. In practice, a dataset of questions without expected answers can still produce safety and groundedness scores, but it cannot produce a correctness score.

    Recommended RAG metrics by dimension, how they are measured, and whether they need ground truth
    MetricDimensionMeasured byNeeds ground truth?
    correctnessResponseLLM judgeYes
    safetyResponseLLM judgeNo
    groundednessResponseLLM judgeNo
    relevance_to_queryResponseLLM judgeNo
    document_recallRetrievalDeterministicYes
    total_token_countCostDeterministicNo
    latency_secondsLatencyDeterministicNo

    Checkpoint 1 of 9· Match them up

    Match each metric from a RAG evaluation run to how it is produced

    Tap a term, then the definition that fits it.

    Checkpoint 2 of 9· Exam question

    A team is comparing three candidate models for a RAG question-answering app. They have curated 200 questions with expected answers and want to score both factual correctness and the presence of unsafe content in each model's responses. Which statement correctly matches each metric type to whether it needs the curated expected answers as ground truth?

    Sources123

    2.Comparing candidates with only the model changed

    A metric difference between two runs only means something if the model is the only thing that changed. Each call to the mlflow.genai.evaluate() harness runs a candidate over an evaluation dataset, scores it with a set of judges, and records the result as its own run. If you also swap the dataset, add a judge or change the prompt between calls, a higher score could come from any of those changes. So keep data and scorers the same in every call and change only the candidate passed as predict_fn.

    A second evaluation run that reuses the dataset and judges and changes only the candidatepython
    import mlflow
    
    # Run evaluation of the new version with the same judges as before
    # Use start_run to name the evaluation run in the UI
    with mlflow.start_run(run_name="v2"):
        eval_results_v2 = mlflow.genai.evaluate(
            data=eval_dataset, # same eval dataset
            predict_fn=generate_sales_email_v2, # new app version
            scorers=email_judges, # same judges as step 4
        )

    Naming each run with run_name lets you find the candidates in the UI. To compare them there, open the experiment and click Evaluation runs. Check the runs you want, then choose Compare from the Actions menu. The right pane lines up every trace from the selected runs, so you can open the same request and see how each candidate answered it, along with each judge's assessment.

    From code, fetch each run with mlflow.search_runs(filter_string=f"run_id = '{...}'") and put the per-judge /mean metric columns side by side. search_runs does not support IN or OR, so fetch the runs one at a time. In the reference tutorial, the new version improved its average quality score by +0.143 overall. In the same comparison, retrieval_groundedness fell from 0.857 to 0.571. An average can hide a regression on exactly the dimension your application can't afford to lose, so read the result one metric at a time, and then open the traces where a score dropped.

    Checkpoint 3 of 9· Check yourself

    A team scored candidate v1 with mlflow.genai.evaluate() on a 100-question dataset using four judges. For v2, they passed a new predict_fn, added a fifth judge and extended the dataset to 150 questions. v2's average score is higher. What should they conclude?

    Sources4

    3.Requirements as pass/fail gates, then one deciding metric

    Treat some metrics as requirements and one metric as the decision. Safety is usually a requirement: a candidate that fails the safety judge is out, however well it scores elsewhere. Latency and cost often come from a budget, such as a response-time limit or a spending cap. A candidate either meets the budget or it doesn't. Once every remaining candidate passes all the gates, the gate metrics no longer tell you which one to pick. The decision falls to the metric where the candidates still differ, which is usually a quality score such as correctness.

    The reference tutorial keeps the two kinds of metric apart in code. Its comparison script drops the agent/ metrics (latency and token counts) before it averages quality scores. Mixing them would let a fast but weaker candidate look better on a single blended number. Check latency and tokens against your budgets on their own, and compare candidates on quality.

    MLflow doesn't decide which metric matters. The Sort dropdown in the chart view and the order_by argument of the Logged Model search both rank by whatever field you give them. The ranking metric comes from the application's requirements, not from a built-in default such as cost per token. One more thing to check: if a scorer is reference-based, its numbers came from your expected answers. Correctness scores are therefore grounded in ground truth, and you shouldn't throw them out as unreliable.

    Checkpoint 4 of 9· Check yourself

    Three candidate chatbots were scored on the same dataset with the same judges. Candidate C has the highest correctness, 0.93, but fails the safety judge. Candidates A (0.88 correctness) and B (0.84 correctness) both pass safety and both stay within the latency and token budgets. B is faster and uses fewer tokens. Which selection is right?

    Checkpoint 5 of 9· Exam question

    A generative AI engineer runs an MLflow evaluation comparing two candidate models for a support-ticket summarization app. Both models pass the safety judge, and both comfortably beat the end-to-end latency budget. Model A scores 0.92 on the correctness scorer while Model B scores 0.81 but responds about twice as fast. Based on the logged experiment metrics, which model should be selected?

    Sources45

    4.Filtering, charting and ranking runs and Logged Models

    With dozens of runs, filter first and compare second. The search box on the experiment page takes expressions over parameters, metrics and tags. Each expression narrows the runs table to the candidates that clear a bar:

    Run search expressions and what they select
    ExpressionSelects runs where
    metrics.r2 > 0.3the last logged r2 value is above 0.3
    params.elasticNetParam = 0.5 AND metrics.avg_areaUnderROC > 0.3a parameter value and a metric threshold both hold
    MIN(metrics.rmse) <= 1the lowest rmse ever logged in the run is at most 1
    MAX(metrics.memUsage) > 0.9the highest memUsage logged in the run is above 0.9
    tags.estimator_name="RandomForestRegressor"the run carries that tag value

    A plain metric filter checks the last logged value, not the best value the run ever reached. To filter on the best or worst value, use MIN or MAX, and note that only runs logged after August 2024 store those values. The Time created, State and Datasets dropdowns narrow the list further. The Datasets filter helps keep a comparison to runs that were scored on the same evaluation set.

    The chart view turns the filtered runs into pictures. By default it shows the 10 most recent runs, and hovering over a line shows that run's details. The Sort dropdown reorders the runs and Group by groups them by a parameter value. A parallel coordinates plot shows how parameter settings relate to a metric. In the docs' example, lower values of max_depth lined up with higher auc.

    In MLflow 3, the candidate itself is a first-class object. The MLflow 3 LoggedModel is a model entity with an ID that links its parameters, metrics and traces across runs. The experiment's Models tab lists every LoggedModel with its metrics, and you can search, filter and chart them just like runs. Metric filters can be limited to a specific dataset, so a model only matches if it hit the threshold on that dataset. The API version filters to the candidates above a bar and sorts them by the deciding metric:

    Filter Logged Models on a metric for one dataset and order them by that metricpython
    ## Get all Logged Models greater than a specific metric value on a dataset, then order by that metric value
    mlflow.search_logged_models(
      filter_string = "metrics.<metric_name> >= <metric_value>",
      datasets = [
        {"dataset_name": <dataset_name>, "dataset_digest": <dataset_digest>}
      ],
      order_by = [
        {"field_name": metrics.<metric_name>, "dataset_name": <dataset_name>,"dataset_digest": <dataset_digest>}
      ]
    )

    To trace a top-ranked model back to the evaluations behind its score, run mlflow.search_runs(filter_string = "models.model_id = <my-model-id>"). It returns every run that used the model as an input or produced it as an output. Promotion goes through the Models tab's Charts view, where you compare candidates and pick the versions to register in Unity Catalog. In Catalog Explorer, the model version page then gathers that version's metrics and traces from every linked environment. When you use a deployment job, its evaluation task adds more metrics to that page, and the job's approver reviews them before approving the version for deployment.

    Checkpoint 6 of 9· Fill the gap

    Which call completes this sample so it returns candidate models that clear a metric bar on one evaluation dataset, ranked by that metric?

    ## Get all Logged Models greater than a specific metric value on a dataset, then order by that metric value
    mlflow. ? (
      filter_string = "metrics.<metric_name> >= <metric_value>",
      datasets = [
        {"dataset_name": <dataset_name>, "dataset_digest": <dataset_digest>}
      ],
      order_by = [
        {"field_name": metrics.<metric_name>, "dataset_name": <dataset_name>,"dataset_digest": <dataset_digest>}
      ]
    )

    Checkpoint 7 of 9· Check yourself

    Run R, logged in 2025, recorded correctness three times during evaluation: 0.94, then 0.91, then 0.86. You enter metrics.correctness > 0.9 in the experiment search box. What happens to R?

    Sources6578

    5.Context length as a gate when choosing an embedding model

    Embedding models follow the same gate-then-compare rule, and one of the gates comes from the model card rather than from an experiment. That gate is the maximum token limit. A chunk longer than the limit is truncated before it is embedded, so the text past the cutoff never makes it into the vector and can't be retrieved. bge-large-en-v1.5, for example, has a limit of 512 tokens. Choosing a context length in general belongs to embedding model context length selection. Here the limit acts as a gate.

    Take a contract-search pipeline that chunks clauses at up to 6,000 tokens. Any embedding model whose documented maximum is below 6,000 drops the end of the longest clauses, whatever its benchmark score. Start by removing those models. Then compare the remaining ones on retrieval metrics from your own experiments, because public leaderboards such as MTEB may not reflect the characteristics of your data. A model ranked lower on MTEB can still win on your evaluation set.

    Checkpoint 8 of 9· Check yourself

    Your support-ticket search pipeline chunks tickets at up to 2,000 tokens. You are choosing between three embedding models. X tops the MTEB retrieval leaderboard and has a documented maximum of 512 tokens. Y allows 4,096 tokens and Z allows 8,192, and both rank lower on MTEB. Which selection process is right?

    Checkpoint 9 of 9· Exam question

    A team is building a retrieval system over legal contracts where individual clauses are chunked at up to 6,000 tokens each. While comparing embedding model cards to select a model for this pipeline, which approach correctly uses the context length metric to guide the decision?

    Sources9

    Sources

    (10)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “Below is a summary of the metrics that Databricks recommends for measuring the quality, cost, and latency of your RAG application.”
      ↩︎ What the metrics in an experiment measure
      “Cost and latency metrics can be computed deterministically based on the application's outputs.”
      ↩︎ What the metrics in an experiment measure
      “Other LLM judges, such as groundedness, do not require human-labeled ground truth to assess their app outputs.”
      ↩︎ Exam trap 1
      “Some LLM judges, such as answer correctness, compare the human-labeled ground truth vs. the app outputs.”
      ↩︎ Prediction
    2. 2.
    3. 3.
      “In an experiment, you can compare and filter runs to understand how your model performs and how its performance depends on the parameter settings”
      ↩︎ What the metrics in an experiment measure
    4. 4.
      “Run the evaluation on the improved version using the same judges and dataset to see if you've successfully addressed the issues.”
      ↩︎ Comparing candidates with only the model changed
      “Look for specific examples where the evaluation metrics regressed so you can focus on those.”
      ↩︎ Comparing candidates with only the model changed
      “Skip the agent metrics (latency, token counts) for quality comparison”
      ↩︎ Requirements as pass/fail gates, then one deciding metric
      “Run the evaluation on the improved version using the same judges and dataset to see if you've successfully addressed the issues.”
      ↩︎ Key concept
      “Skip the agent metrics (latency, token counts) for quality comparison”
      ↩︎ Exam trap 2
    5. 5.
      “To change the sort order of runs shown in the charts, select the parameter to sort by from the Sort dropdown menu.”
      ↩︎ Requirements as pass/fail gates, then one deciding metric
      “A parallel coordinates plot is useful in understanding the effect of parameter settings on model performance”
      ↩︎ Filtering, charting and ranking runs and Logged Models
    6. 6.
      “Using MIN or MAX lets you search for runs based on the minimum or maximum metric values, respectively.”
      ↩︎ Filtering, charting and ranking runs and Logged Models
      “By default, metric values are filtered based on the last logged value.”
      ↩︎ Exam trap 3
      “By default, metric values are filtered based on the last logged value.”
      ↩︎ Checkpoint
    7. 7.
      “You can filter metrics based on dataset-specific performance, and only models with matching metric values on the given datasets are returned.”
      ↩︎ Filtering, charting and ranking runs and Logged Models
      “Get all Logged Models greater than a specific metric value on a dataset, then order by that metric value”
      ↩︎ Checkpoint
      “You can filter metrics based on dataset-specific performance, and only models with matching metric values on the given datasets are returned.”
      ↩︎ Checkpoint
    8. 8.
      “provides visualizations to help you compare models and select the model versions to register to Unity Catalog for possible deployment”
      ↩︎ Filtering, charting and ranking runs and Logged Models
      “The approver for the job can then review this page to assess whether to approve the model version for deployment.”
      ↩︎ Filtering, charting and ranking runs and Logged Models
    9. 9.
      “For example, bge-large-en-v1.5 has a maximum token limit of 512.”
      ↩︎ Context length as a gate when choosing an embedding model
      “Experiment with different off-the-shelf embedding models, even those that may be lower-ranked on standard leaderboards like MTEB.”
      ↩︎ Context length as a gate when choosing an embedding model
      “If you pass chunks that exceed this limit, they will be truncated, potentially losing important information.”
      ↩︎ Exam trap 4

    Also cited

    Spotted a mistake, or was something unclear? Tell us.