Redirect RAG Evaluation - AI & ML Evaluation Roadmap 2026
← Back to Tutorials

4. RAG Evaluation

Part 4

Retrieval-augmented generation (RAG) has two halves that must both work: the retriever finds useful context, and the generator turns that context into an answer. A weak retriever starves the model; a weak generator ignores good context. This part covers evaluating both halves and the pipelines built around them.

Retrieval Quality

Retrieval quality is a ranking problem: given a query, are the relevant documents near the top? Measure it with the ranking metrics from Part 2 — Recall@K, Precision@K, MRR, MAP, and NDCG — where "relevance" means "this chunk contains the information needed to answer the question." Build a labeled set of query-to-relevant-chunk pairs and score the retriever on it independently of the generator.

Chunk Quality

How you split documents into chunks determines what the retriever can find. A chunk that splits a sentence in half, or mixes two unrelated topics, produces bad matches no matter how good the embedding model is. Evaluate chunking by checking how often the full answerable information lands in one retrievable chunk. Strategies to test: fixed-size windows with overlap, semantic splitting on paragraph or heading boundaries, and recursive splitting on structure.

Embedding Quality

The embedding model decides how "similar" two texts are in vector space. Good embeddings place paraphrases of the same meaning close together and unrelated topics far apart. Test them with a small set of pairs (query, relevant doc, hard negative) and check retrieval metrics or direct similarity separation. When you change embedding models, re-run the retrieval evaluation — small embedding changes can shift results noticeably.

Reranker Evaluation

A reranker re-scores the top K candidates to sharpen the ordering. To judge whether reranking actually helps, compare ranking metrics with and without the reranker on the same queries. Track both quality (NDCG) and the added latency, since a reranker that buys 2% NDCG at triple the latency may not be worth it.

Context Precision

Context precision asks whether the retrieved context is on-topic: are the chunks the system actually pulled relevant to the question, and are the relevant chunks ranked high enough? Low context precision means the generator is being given mostly irrelevant material and must fight through noise.

Context Recall

Context recall asks whether the retrieved set is complete: did the system find everything needed to answer well? A retriever can have high precision and still miss a key document, forcing the model to guess. The strongest signal is failure analysis — when answers are wrong, check whether the needed fact was even in the context.

MetricQuestionFailure symptom
Context precisionIs what we retrieved relevant?Answers ramble about unrelated topics
Context recallDid we retrieve everything needed?Answers confident but missing the key fact
Citation accuracyDo citations match the answer?Claim does not appear in the cited chunk
Hallucination rateIs content grounded in context?Fabricated names, numbers, or sources

Citation Accuracy

When answers cite sources, each claim should actually appear in the cited chunk. Manually or automatically verify every citation. A high citation rate with low citation accuracy is a false sense of security — users trust citations that point to content that never said what you claimed.

Hallucination Analysis

In RAG, hallucination is usually a grounding failure: the model produced a statement not present in the retrieved context. Separate the failure causes: was the fact missing from the context (retrieval problem), or present but contradicted by the model (generation problem)? That split tells you which half of the pipeline to fix.

RAGAS

RAGAS is an open-source framework that scores RAG pipelines with LLM-judged metrics: faithfulness (answer vs context), answer relevance, context precision, and context recall. Because it computes without hand-labeled data, it is a fast way to get a baseline across many queries.

from ragas import evaluate
from ragas.metrics import faithfulness, context_precision, context_recall

results = evaluate(dataset, metrics=[
    faithfulness, context_precision, context_recall
])
print(results)
Watch out: LLM-judged RAGAS scores inherit the judge's biases and can drift when you swap the judge model. Anchor them to a hand-labeled set.

DeepEval

DeepEval provides a metric library and a test harness for LLM and RAG applications. You write test cases declaring expected answers, and DeepEval computes metrics like answer relevance, faithfulness, and hallucination, then produces a pass/fail report you can wire into CI.

TruLens

TruLens focuses on monitoring RAG (and other) applications in production. It instruments each pipeline run, records the feedback metrics per record, and shows trends over time so you can spot a retrieval regression or a drop in groundedness before users complain.

Practice Task: Pick ten documents you know well, write five questions, and identify which chunks answer each. Run a retriever of your choice and compute Recall@3 and MRR. Then check, for three wrong answers from any RAG system, whether the missing fact was in the context. Write down which failures were retrieval problems and which were generation problems.