Slides · Retrieval-augmented generation
RAG evaluation in depth
1 / 24
RAG evaluation in depth
“Is it fine, yes or no?” needs more than one number. This lesson builds an evaluation that says which stage is responsible and how far to trust the score.
By the end you can:
- design an evaluation that scores retrieval and generation separately, then end to end,
- compute recall@k, precision@k and MRR by hand,
- turn misses into a failure taxonomy,
- build a golden set with unanswerable questions and use an LLM judge with care,
- run controlled experiments that track quality, latency and cost together.
Concept
Three complaints, one number
- One user got a wrong page.
- One got an old page.
- One got the right page, read badly.
A single quality score blends all three. Each needs a different fix: retrieval, source freshness, generation. You need numbers that point at a stage.
Diagram
The evaluation, stage by stage
Think of an inspection of the kitchen, the plating and the whole meal. A single satisfaction number cannot say whether the ingredients or the cooking was at fault.
Concept
Three retrieval metrics, three questions
- Recall@k: was the evidence found in the top k? The first metric to read: if the evidence is not retrieved, generation cannot fix it.
- Precision@k: how much of the top k is relevant? Low precision means a noisy prompt.
- MRR: how high did the first relevant chunk rank? Useful when one good chunk is enough.
nDCG@k additionally rewards putting highly relevant items earlier and handles graded relevance.
All of these need labelled relevant chunks for each query.
Math
The formulas
The worked examples below use the hit rate, which many teams simply call recall@k.
hit raterecall@kprecision@kMRR=total queriesqueries with a relevant chunk in the top k=all relevant chunks for that queryrelevant chunks in the top k=krelevant results in the top k=N1i=1∑Nranki1,with ranki1=0 when nothing relevant is found| Symbol | Meaning |
|---|---|
| k | How many top results you look at |
| hit rate | Share of queries with at least one relevant chunk in the top k; often reported as recall@k |
| recall@k | Per query: how many of the relevant chunks were found; average over queries |
| N | Number of queries |
| ranki | Position of the first relevant result for query i, starting at 1 |
| 1/ranki | Reciprocal rank: 1 for first place, 21 for second, 31 for third |
Note that MRR looks only at the first relevant result; later relevant results do not count.
Source[1] Mean reciprocal rank
Worked example
Worked example: four queries, top 5
First relevant chunk is at rank 1, rank 3, not found, and rank 2.
| Query | Rank of first relevant | In top 5? | Reciprocal rank |
|---|---|---|---|
| A | 1 | yes | 1.000 |
| B | 3 | yes | 0.333 |
| C | none | no | 0 |
| D | 2 | yes | 0.500 |
Recall@5 says three of four were found. MRR adds how high they ranked, which matters if only the top few go into the prompt.
Source[1] Mean reciprocal rank
Worked example
Worked example: precision and what k changes
One query returns five results. Relevant ones are at ranks 1, 2, 3 and 5.
precision@5precision@3precision@1=54=0.8=33=1.0=11=1.0- The same list looks perfect at k=3 and still carries one noisy chunk at k=5.
- Choose k to match how many chunks you really put in the prompt.
- A single query gives precision. Recall over the set needs the fraction of queries (or relevant chunks) found.
Worked example
Worked example: which metric moves?
Five queries, top 3 for recall. First relevant ranks: 1, none, 4, 2, none.
recall@3=52=0.40MRR=51+0+0.25+0.5+0=0.35Now an engineer improves one query: rank 4 becomes rank 1.
recall@3=53=0.60MRR=51+0+1+0.5+0=0.50Recall@3 rose because the chunk crossed into the top 3. MRR rose because it moved up. If a chunk moves from rank 2 to rank 1, recall@3 does not change at all, but MRR does. Use both.
Concept
Generation metrics
- Faithfulness (groundedness): is every claim supported by the retrieved context? Split the answer into claims and check each, with a judge model or an entailment model.
- Answer relevance: does it address the question?
- Answer correctness: does it match the gold answer?
- Citation accuracy: do cited sources support the cited claims?
- Abstention quality: does it say “I don’t know” when the context lacks the answer?
The Ragas documentation defines faithfulness as supported claims divided by total claims. The Ragas paper presents metrics for the retriever, the faithful use of context and generation quality.
Sources[2] RAGAs: Automated Evaluation of Retrieval Augmented Generation[3] Faithfulness
Compare
The failure taxonomy
| Retrieved gold? | Answer faithful? | Answer correct? | Diagnosis |
|---|---|---|---|
| No | any | No | Retrieval failure |
| Yes | Yes | No | Source wrong or ambiguous, or the question is ambiguous |
| Yes | No | No | Generation failure |
| No | No | Yes, by luck | From model memory, not the corpus: risky |
| Yes | Yes | Yes | Healthy |
Quick manual check: paste the gold passage into the prompt. If the answer is now correct, the retriever was the problem.
Worked example
Worked example: four misses, four rows
Illustrative results from a run.
| Miss | Gold chunk retrieved? | Faithful? | Correct? | Row and first fix |
|---|---|---|---|---|
| M1 | No | n/a | No | Retrieval: check chunking and add hybrid search |
| M2 | Yes | Yes | No | Source or ambiguity: read the gold chunk; fix the document |
| M3 | Yes | No | No | Generation: tighten grounding, trim noisy context |
| M4 | No | No | Yes | Memory, not corpus: add the question to the regression set and require citations |
M4 looks like a win and is not. It passes today and fails when the model changes.
Diagram
A golden set is a living asset
Concept
Golden set rules
- Start from real logged queries and subject-matter experts. Tens of questions to begin, a few hundred is better.
- Cover types: factual, multi-hop, ambiguous, unanswerable, exact-ID, long-form.
- Label gold chunks, not just answers, so retrieval can be scored.
- Synthetic questions scale the set, but they tend to be easier and echo the chunk’s wording. Review a sample by hand.
- Slice by query type, document type, tenant and language. An average can hide a failing slice.
Concept
LLM-as-judge: useful, biased
A judge model scores answers at scale. The MT-Bench paper reports that strong judges reach over 80% agreement with human preferences, and it names position, verbosity and self-enhancement bias as limitations.
| Pitfall | What happens | Mitigation |
|---|---|---|
| Position bias | Favours an answer by where it appears | Swap the order and compare |
| Verbosity bias | Favours longer answers | Fixed rubric, length-aware checks |
| Self-enhancement | Favours its own answers, and plausibly those of its own model family | Judge from a different family |
| Instability | Scores differ across runs | Repeat or vote; calibrate against human labels |
Report agreement with human labels for your own rubric. A judge you have not calibrated is an opinion.
Source[4] Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena
Diagram
Cancelling position bias
Concept
Do not rely on temperature 0 for a stable judge
- Temperature 0 alone does not guarantee identical output. The Thinking Machines article attributes it mainly to kernels that are not batch-invariant, so results depend on server load.
- Some current models restrict sampling parameters. The Claude Sonnet 5.5 migration guide says temperature, top_p and top_k return an error and should be removed.
- So stability comes from design: a fixed rubric, structured output, repeated judging or a majority vote, and human calibration.
Check your model’s current documentation before choosing settings.
Sources[5] Defeating Nondeterminism in LLM Inference[6] Claude Sonnet 5.5 migration guide
Process
One change at a time
- Pick one change: chunk size, embedder, reranker or prompt.
- Run it on the same golden set as the baseline.
- Read quality, latency and cost together.
- Report uncertainty: on a small set one question is a visible jump.
- Slice the results; look for a group that got worse.
- Gate the deploy on thresholds you set before you looked.
Changing three things in one release leaves you unable to say which one helped.
Worked example
Worked example: a gain that costs
Illustrative experiment on 250 golden queries: a larger embedding model.
| Measure | Baseline | Candidate | Change |
|---|---|---|---|
| recall@5 | 0.74 | 0.78 | +0.04 |
| p95 latency | 0.9 s | 1.1 s | +0.2 s (about 22 percent) |
| Cost per 1,000 queries | $2.00 | $2.60 | +30 percent |
Ten queries out of 250 is a small shift; check which queries flipped before calling it real. Decide using a rule written beforehand, for example “ship if recall@5 gains at least 3 points on every slice, with latency under 1.2 s and cost within 25 percent”. By that rule this candidate fails on cost, however good the recall looks.
Concept
Online signals feed the offline set
- Thumbs up or down, copy and edit rate, follow-up rephrasing, escalation to a human.
- “No answer” rate, citation clicks, latency and cost per query.
- Sample low-signal traces for human review and add the failures to the golden set.
- Wire the golden set into CI, so a change that drops recall@k on a slice fails the build.
Tools such as Ragas, TruLens, DeepEval, LangSmith and Arize Phoenix exist, and features change often, so check current documentation before choosing.
Check yourself
Check: compute and diagnose
Six queries, first relevant rank in the top 5: 1, 1, 3, none, none, 5. (a) Compute recall@3 (hit rate) and MRR. (b) For one of the “none” queries the gold chunk was missing from the retrieved list and the answer was wrong. Which taxonomy row is it, and what do you try first?
Answer
(a) Recall@3 =63=0.50 (ranks 1, 1 and 3 qualify; rank 5 is outside the top 3). MRR =61+1+0.333+0+0+0.2=62.533=0.422. (b) Gold not retrieved and answer wrong is a retrieval failure; try chunking, hybrid search or metadata filters first.
Check yourself
Check: spot the flaws
A team builds a 60-question set by asking a model to write one question per chunk, runs a pairwise judge that always shows the baseline answer first, and picks the release threshold after seeing the new results. They report “answer quality up 3 points”. List three problems and a fix for each.
Answer
- Synthetic questions copied from chunks are easy and echo their wording; add reviewed real queries and unanswerable ones. 2. Always showing the baseline first invites position bias; judge both orders and treat a flip as a tie or send it to a human. 3. A threshold chosen after seeing results is fitted to them; set the rule beforehand. Also: 3 points on 60 questions is about two flips (each is 1.7 points), so confirm on a larger set and report the retrieval and generation metrics separately.
Summary
Recap
- Evaluate stages separately, then end to end.
- Recall@k: found it? MRR: how high? Precision@k: how noisy?
- Faithfulness, relevance, correctness, citation accuracy, abstention.
- The taxonomy names who is responsible for each miss.
- Golden sets need unanswerable questions, gold chunks, a frozen and a fresh part.
- Judges are biased: calibrate against human labels.
- One change at a time; track quality, latency and cost; report uncertainty.
References
References & Sources (1 of 2)
Mean reciprocal rank (opens in a new tab)
Wikipedia2026Article
https://en.wikipedia.org/wiki/Mean_reciprocal_rank
Used for MRR averages the reciprocal of the rank of the first correct answer per query, scores 0 when there is none, and considers only the first relevant result.
RAGAs: Automated Evaluation of Retrieval Augmented Generation (opens in a new tab)
Shahul Es, Jithin James, Luis Espinosa-Anke, Steven Schockaert2024EACL 2024 (System Demonstrations)Paper
arXiv 2309.15217 (opens in a new tab)https://arxiv.org/abs/2309.15217
Used for Ragas proposes reference-free metrics covering the retriever's ability to find focused context, the model's faithful use of it, and generation quality.
Faithfulness (opens in a new tab)
Ragas2026Documentation
https://docs.ragas.io/en/stable/concepts/metrics/available_metrics/faithfulness/
Used for Faithfulness is the number of response claims supported by the retrieved context divided by the total number of claims.
Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena (opens in a new tab)
Lianmin Zheng, Wei-Lin Chiang, Ying Sheng, Siyuan Zhuang, et al.2023NeurIPS 2023 Datasets and Benchmarks TrackPaper
arXiv 2306.05685 (opens in a new tab)https://proceedings.neurips.cc/paper_files/paper/2023/hash/91f18a1287b398d378ef22505bf41832-Abstract-Datasets_and_Benchmarks.html
Used for Strong LLM judges reach over 80 percent agreement with human preferences, and position, verbosity and self-enhancement biases are limitations.
Defeating Nondeterminism in LLM Inference (opens in a new tab)
Horace He2025Article
https://thinkingmachines.ai/blog/defeating-nondeterminism-in-llm-inference/
Used for Temperature 0 does not by itself make LLM inference repeatable, because kernel results can depend on server load.
References
References & Sources (2 of 2)
Claude Sonnet 5.5 migration guide (opens in a new tab)
Anthropic2026Documentation
https://platform.claude.com/docs/en/models/sonnet-5-5/migration-guide
Used for The Claude Sonnet 5.5 guide says temperature, top_p and top_k return an error and should be removed.
Keys: ← → move, Home End first and last, F full screen.