RAG Evaluation

RAG evaluation measures how well a retrieval-augmented generation (RAG) application finds the right documents and how faithfully it uses them to answer. A complete RAG evaluation scores three things separately: whether the retrieved chunks are relevant, whether they are sufficient to answer the question, and whether the final response is grounded in them.

MLflow provides a built-in LLM judge for each of these checks: RetrievalRelevance, RetrievalSufficiency, and RetrievalGroundedness. You run them with mlflow.genai.evaluate(), and MLflow Tracing records every retrieval so you can see exactly which chunks produced each score.

Last updated: November 26, 2026

MLflow Evaluation runs page showing a trend chart of correctness, groundedness, relevance, and safety scores across three evaluation runs, with a table of runs and their mean scores
The MLflow Evaluation runs page compares judge scores across runs (shown with MLflow's demo data).

Quick Navigation:

Why Is RAG Evaluation Different from LLM Evaluation?

A RAG application has two stages that can fail independently. The retriever can return the wrong documents, and the language model can ignore or contradict the documents it was given. A single "is the answer good?" score hides which stage broke, so you end up tuning prompts when the real problem is chunking, or swapping retrievers when the real problem is hallucination.

Evaluating each stage separately turns a vague quality problem into a specific one. The three most common RAG failure modes each have a matching check:

Failure modeWhat you seeCheck with
Poor retrievalRetrieved documents are off-topic for the questionRetrievalRelevance
Insufficient contextDocuments are on-topic but miss facts needed to answerRetrievalSufficiency
HallucinationThe answer states things the retrieved documents do not supportRetrievalGroundedness

What Metrics Does MLflow Provide for RAG Evaluation?

MLflow's built-in RAG judges cover retrieval quality and grounding. Pair them with general response-quality judges to cover the answer itself.

JudgeQuestion it answersNeeds ground truth?Needs a trace?
RetrievalRelevanceIs each retrieved chunk relevant to the user's request?NoYes
RetrievalSufficiencyDo the retrieved chunks contain everything needed to answer?Yes (expected facts or response)Yes
RetrievalGroundednessIs the response supported by the retrieved chunks?NoYes
CorrectnessDoes the response contain the expected facts?Yes (expected facts or response)No
RelevanceToQueryDoes the response address the user's question?NoNo

RetrievalRelevance scores each retrieved chunk individually, so you can see which documents in a result set are noise. All three retrieval judges read the retrieved documents from the trace, which is why your retriever needs a span of type RETRIEVER.

How Do You Evaluate a RAG Application with MLflow?

The workflow has three steps: instrument the retriever, define test questions with expected facts, and run the judges.

Step 1: Instrument your retriever

Decorate the function that fetches documents with @mlflow.trace(span_type="RETRIEVER") and return MLflow Document objects. If you use a framework such as LangChain or LlamaIndex, MLflow's autologging can record retriever spans for you.

python
import mlflow
import openai
from mlflow.entities import Document
mlflow.openai.autolog() # traces the LLM call too
client = openai.OpenAI()
@mlflow.trace(span_type="RETRIEVER")
def retrieve_docs(query: str) -> list[Document]:
# Replace with a query to your vector database
return [
Document(
id="doc_1",
page_content="MLflow is an open source AI engineering platform ...",
metadata={"source": "mlflow_overview.txt"},
)
]
@mlflow.trace
def rag_app(query: str):
docs = retrieve_docs(query)
context = "\n\n".join(d.page_content for d in docs)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{
"role": "system",
"content": f"Answer using only this context:\n\n{context}",
},
{"role": "user", "content": query},
],
)
return {"response": response.choices[0].message.content}

Step 2: Run the RAG judges

Pass your application as predict_fn and the RAG judges as scorers. Each row of the dataset is run through your application, traced, and scored.

python
import mlflow
from mlflow.genai.scorers import (
RetrievalRelevance,
RetrievalSufficiency,
RetrievalGroundedness,
Correctness,
)
results = mlflow.genai.evaluate(
data=dataset,
predict_fn=rag_app,
scorers=[
RetrievalRelevance(model="openai:/gpt-4o-mini"),
RetrievalSufficiency(model="openai:/gpt-4o-mini"),
RetrievalGroundedness(model="openai:/gpt-4o-mini"),
Correctness(model="openai:/gpt-4o-mini"),
],
)

Open the run in the MLflow UI to compare scores, filter to low-scoring rows, and click through to the trace behind each one. Run the same dataset after every change to your chunking, embedding model, retriever settings, or prompt, and compare runs side by side.

How Do You Build a RAG Evaluation Dataset?

A good RAG test set mixes the questions users actually ask with the hard cases you worry about: multi-document questions, questions the knowledge base cannot answer, and near-duplicate topics. Each record has inputs (the arguments to your predict_fn) and optional expectations holding the facts a correct answer must contain.

python
from mlflow.genai.datasets import create_dataset
dataset = create_dataset(name="rag_eval_v1")
dataset.merge_records(
[
{
"inputs": {"query": "What does MLflow offer for agents and LLMs?"},
"expectations": {
"expected_facts": [
"MLflow is an open source AI engineering platform",
"Features include observability and evaluation",
]
},
},
]
)

You can also seed a dataset from production traces with mlflow.search_traces(), which keeps your test set close to real traffic. See the evaluation datasets documentation for versioning and record management.

How Do You Debug RAG Failures with Traces?

A low score tells you something is wrong; the trace tells you why. Because MLflow evaluates your application through tracing, every scored row links to a trace showing the query, the retrieved chunks, the prompt sent to the model, and the final answer. That makes the usual diagnoses quick:

  • Low RetrievalRelevance: inspect the retrieved chunks. Check embedding model choice, chunk size, top-k, and metadata filters.
  • Low RetrievalSufficiency with good relevance: the right documents are retrieved but the needed fact is in a chunk you did not return. Increase top-k, adjust chunk overlap, or add reranking.
  • Low RetrievalGroundedness: the model is adding unsupported claims. Tighten the system prompt, lower temperature, or require citations.
  • Low Correctness with high groundedness: the answer faithfully reflects wrong or outdated documents. Fix the knowledge base, not the prompt.

Learn more about capturing these spans in LLM tracing with MLflow.

Can You Add Custom or Third-Party RAG Metrics?

Built-in judges are a starting point. For domain rules, such as "the answer must cite a source" or "never recommend a competitor", create a custom LLM judge with make_judge(), or write a code-based scorer with the @scorer decorator. To use metrics from other libraries, MLflow offers integrations for RAGAS, DeepEval, and others that run through the same mlflow.genai.evaluate() call.

LLM judges are themselves models, so validate them. Spot-check verdicts against your own judgment and use human feedback to align a judge before relying on its scores in a release gate.

MLflow is the open source AI engineering platform for agents, LLMs, and ML models. It is licensed under Apache 2.0 and backed by the Linux Foundation, so RAG evaluation, tracing, and datasets run on your own infrastructure with no per-evaluation fees. Read the RAG evaluation guide →

Frequently Asked Questions

RAG evaluation is the process of measuring how well a retrieval-augmented generation application retrieves relevant documents and how faithfully its generated answer uses them. A complete RAG evaluation scores retrieval quality (relevance and sufficiency of the retrieved chunks) and generation quality (groundedness, correctness, and relevance of the answer) separately, so you can tell whether a bad answer came from the retriever or from the language model.

Related Resources