Evaluating retrieval and answer quality
medium 6 minEvaluate retrieval and generation separately using the same questions.
Find the pages, check the claims, answer the reader.
A librarian lays out the requested pages, checks each sentence against them and rereads the reader’s question.
Video lesson · Chapter 1 of 4
A faithful answer to another question
Theory
Read or listen first. About 2 min.
What it is
Evaluate retrieval and generation separately using the same questions. Document-level labels reveal missed evidence, while claim-level checks reveal unsupported assertions. A response can score well on one measure and poorly on another without either measurement being wrong.
Why it exists
Freeze the corpus and evaluation snapshot before comparing changes. Use examples with missing facts, distractors and multi-document answers, and inspect individual failures rather than optimizing a single blended score.
A faithful answer to the wrong question
Inside this chapter
Chapter sources- Synthetic Data Generation
- Generate evaluation questions from representative documents, then verify their answers and evidence. Include noisy, multi-source and unanswerable cases. Keep generated questions separate from tuning data and add human-authored cases to detect a generator that routinely asks only easy questions.
Generated questions are cheap but skewed: a model reading one passage tends to ask easy questions that reuse the passage's own words, which flatters lexical search. Verify each answer and its evidence, deliberately add questions that need two passages or that the corpus cannot answer, and mix in human-written questions from real logs. Keep this set separate from anything used to tune prompts or train retrievers.
Example. Generate questions from a known passage, then add one human-authored question the passage cannot answer. Check both answerability labels.
Another example. A team generates 500 questions from their billing docs and gets 95% recall. Adding 50 real customer questions drops it sharply, because customers write "why was I charged again" rather than "duplicate invoice policy". Illustrative figures.
Building a test set you can trust - 1Sample passagesacross products and dates
- 2Generate questionsmodel writes Q and answer
- 3Verifyhuman or check confirms evidence
- 4Add hard casesmulti-source and unanswerable
- 5Freeze and versionnever reuse for tuning
- Metrics Deep Dive
- Retrieval recall asks whether relevant material was found. Context precision checks the usefulness or ordering of retrieved context under the chosen metric. Faithfulness measures support for answer claims, while answer relevance asks whether the response addresses the question. These dimensions can move in opposite directions.
Retrieval metrics compare the returned set with labelled gold passages; answer metrics compare the response with the context and the question. They fail independently: high recall with a generator that ignores evidence, or a faithful answer that addresses only half the question. Report them separately per slice, and read a sample of failures for each before deciding what to change.
Example. Three passages are retrieved, one is relevant, and two relevant passages exist. Compute precision ⅓ and recall ½ before inspecting the answer.
Four dimensions, one example
Metric Asks Example value Recall@3 Did we find the gold passages? 1 of 2 = 0.5 Precision@3 How much of what we found is gold? 1 of 3 = 0.33 Faithfulness Are answer claims supported by context? 2 of 2 claims Answer relevance Does it answer what was asked? Missed the date The same response can be perfectly faithful and still incomplete. - CI/CD for Agents
- Version prompts, retrievers, corpus snapshots, models and evaluation sets together. Run paired regression checks before release and inspect newly failing cases. An offline pass should lead to a monitored rollout; live workloads can contain different languages, document revisions or access constraints.
Treat prompts, retriever settings, encoder version, corpus snapshot and evaluation set as one versioned bundle. Compare old and new on the same questions (a paired comparison) and look at which individual cases flipped from pass to fail. Some checks, such as access control or safety fixtures, must pass outright. Offline success then earns a monitored canary, not an immediate full release.
Example. A release improves retrieval on routine questions but misses the one access-sensitive fixture. Keep authorization as a separate release gate.
A release gate for a RAG change
Authorisation is a hard gate, not one more point in an average. - Rank-aware metrics: MRR and nDCG
- Metrics that reward putting relevant passages near the top, not just somewhere in the top k. MRR looks at the first relevant hit; nDCG discounts every relevant hit by its position and compares with the ideal order.
Rank matters in RAG because only the first few passages reach the prompt. MRR is simple and suits questions with one right passage. nDCG handles graded relevance (highly relevant versus somewhat relevant) and several relevant passages. Use recall at the retrieval stage, where you only need the passage somewhere in the shortlist, and rank-aware metrics after reranking.
Example. Two retrievers both find the gold passage in their top 5. One puts it first (reciprocal rank 1), the other fifth (reciprocal rank 0.2). Recall@5 cannot tell them apart; MRR can.
Mean reciprocal rank and DCG
nDCG@k divides DCG@k by the DCG of the ideal ordering, so it lies between 0 and 1.
How it works
Step through the idea, or press Play.
Labeled question. Two relevant passages
Understand it
Worked example
A faithful answer to the wrong question
- 1
Two relevant passages
Identify gold evidence and the desired answer. Include source version and the exact question so stage-level scores are interpretable.
- 2
1 of 2 gold passages in top 3
Recall at three is one half. Precision at three for this binary-label example is one third. Neither tells you what answer the model produced.
- 3
2 of 2 claims supported
A response can be faithful to the retrieved text and still omit the second requested fact. Evaluate relevance and completeness separately.
Recall and precision at k
Follow the handoffs
Scoring the labelled question at k = 3
| Rank | Passage | Gold? |
|---|---|---|
| 1 | G1 price policy | Yes |
| 2 | D4 shipping FAQ | No |
| 3 | D9 old promotion | No |
| missing | G2 date rule | Gold, not retrieved |
What the scores show
- Retrieval found one of two gold passages
- Both answer claims are supported
- No hallucinated facts
What they hide unless you check
- The date question was never answered
- Missing G2 explains the gap
- Faithfulness alone would call this a pass
Summary
The whole topic in one minute.
Faithfulness asks whether claims follow from context. Even fully supported claims can fail to address the requested information.
Freeze the corpus and evaluation snapshot before comparing changes. Use examples with missing facts, distractors and multi-document answers, and inspect individual failures rather than optimizing a single blended score.