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
Quick Navigation:
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 mode | What you see | Check with |
|---|---|---|
| Poor retrieval | Retrieved documents are off-topic for the question | RetrievalRelevance |
| Insufficient context | Documents are on-topic but miss facts needed to answer | RetrievalSufficiency |
| Hallucination | The answer states things the retrieved documents do not support | RetrievalGroundedness |
MLflow's built-in RAG judges cover retrieval quality and grounding. Pair them with general response-quality judges to cover the answer itself.
| Judge | Question it answers | Needs ground truth? | Needs a trace? |
|---|---|---|---|
RetrievalRelevance | Is each retrieved chunk relevant to the user's request? | No | Yes |
RetrievalSufficiency | Do the retrieved chunks contain everything needed to answer? | Yes (expected facts or response) | Yes |
RetrievalGroundedness | Is the response supported by the retrieved chunks? | No | Yes |
Correctness | Does the response contain the expected facts? | Yes (expected facts or response) | No |
RelevanceToQuery | Does the response address the user's question? | No | No |
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.
The workflow has three steps: instrument the retriever, define test questions with expected facts, and run the judges.
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.
import mlflowimport openaifrom mlflow.entities import Documentmlflow.openai.autolog() # traces the LLM call tooclient = openai.OpenAI()@mlflow.trace(span_type="RETRIEVER")def retrieve_docs(query: str) -> list[Document]:# Replace with a query to your vector databasereturn [Document(id="doc_1",page_content="MLflow is an open source AI engineering platform ...",metadata={"source": "mlflow_overview.txt"},)]@mlflow.tracedef 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}
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.
import mlflowfrom 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.
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.
from mlflow.genai.datasets import create_datasetdataset = 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.
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:
Learn more about capturing these spans in LLM tracing with MLflow.
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 →