Slides · Retrieval-augmented generation
RAG evaluation and hallucination
1 / 20
RAG evaluation and hallucination
Giving a model the right page does not guarantee a right answer. This lesson shows how it still goes wrong, what to add around it, and how to tell what broke.
By the end you can:
- explain why RAG reduces but does not eliminate hallucination,
- choose mitigations and state the limit of each,
- classify a failure as retrieval or generation from a trace,
- measure quality with separate retrieval and generation metrics, and judge a small gain.
Concept
The page was right. The answer was wrong.
- The retrieved page says: delivery takes 3 working days.
- The assistant’s reply to a customer says 13 days.
- Was the page wrong, or the reading of it?
You cannot fix what you cannot locate. This lesson is about locating it.
Concept
RAG reduces hallucination, it does not remove it
Hallucination: the model states something false or unsupported, with confidence.
- RAG gives the model text to answer from, so it has less reason to guess.
- Anthropic says of its own anti-hallucination techniques that they significantly reduce hallucinations but do not eliminate them, and that critical information must still be validated. The same logic holds for grounding a model with retrieved text.
- Mental model: you handed the student the right textbook page. They can still misread it or answer from memory.
Grounding reduces the opportunity to hallucinate. It does not remove the capability. So you add checks around the model, and you measure.
Compare
Three ways to fail with the right context
Invented passage for illustration: “Standard returns are accepted within 14 days. Sale items cannot be returned.”
| What the model answers | Failure | Why |
|---|---|---|
| “Returns are accepted within 30 days.” | Ignores the context | Answered from memory of other shops |
| “All items, including sale items, can be returned within 14 days.” | Misreads the context | Dropped the sale-item exception |
| “Standard returns within 14 days, and a prepaid label is provided.” | Blends in an unsupported claim | The label is not in the passage |
Each failure has a different fix, so naming it matters.
Concept
Why a model can overlook what is in the prompt
- Long inputs are used unevenly. Liu et al. report that models tend to do better when the relevant passage sits near the beginning or end of the input, and worse when it is buried in the middle.
- So a correct chunk buried among weak ones may be underused.
- One reason to rerank and to keep the prompt lean: less noise, better placement.
This is one cause among several. Misreading and blending happen even with a short, clean prompt.
Source[2] Lost in the Middle: How Language Models Use Long Contexts
Concept
A fourth failure that is not the model’s
The retrieved text itself may be wrong, stale or missing.
- The model follows the page faithfully, and the answer is still wrong.
- Fixing the prompt will not help; fix or refresh the source.
- No relevant page and a confident answer means two problems at once: retrieval missed, and nothing told the model to abstain.
The trace, covered below, is how you tell these apart.
Compare
Five mitigations and their limits
| Technique | What it does | Limit |
|---|---|---|
| Grounding instruction | Tells the model to answer only from context and say it does not know otherwise | An instruction, not a guarantee; test its wording for loopholes |
| Citations | Each claim points to a chunk, so unsupported claims show | A citation can point at a chunk that does not say it; check accuracy, not presence |
| Reranking | Best evidence first, weak chunks out | Cannot fix evidence that was never retrieved |
| Retrieval gate | Refuse when the best score is too low | Scores are not comparable across models; calibrate on labelled data |
| Verification pass | A second pass checks claims against the context | Extra latency and cost; the checker can be wrong |
Anthropic’s page lists permission to say “I don’t know”, quote-first grounding (advised for long documents, over 20k tokens), and verifying claims with citations, and it describes quote-based claim checks that retract unsupported claims.
Diagram
How the mitigations fit together
Each box is a layer with its own limit, so no single layer is trusted alone.
Worked example
Worked example: a gate has two ways to be wrong
Illustrative numbers only. A team sets the gate at 0.50 using one embedding model and one kind of question.
| Question | Best chunk score | Gate at 0.50 | Right behaviour | Outcome |
|---|---|---|---|---|
| Answerable, full sentence | 0.71 | Pass | Answer | Correct |
| Not in the docs at all | 0.55 | Pass | Refuse | Wrong answer |
| Answerable, two-word keyword query | 0.48 | Refuse | Answer | Wrong refusal |
- Raising the gate to 0.60 fixes the second row and makes the third row’s wrong refusals more common.
- Scores differ by model and by query type, so one number is rarely right everywhere.
- Fix: calibrate on a labelled set that has answerable and unanswerable questions, by query type, and count both error kinds. Treat the gate as one layer, not the whole defence.
Concept
What a trace must record
For every request, log:
- the question,
- the retrieved chunks, with ids and scores,
- the final prompt sent to the model,
- the answer.
Without logged chunk ids you are guessing. The trace turns “the bot is wrong” into “retrieval missed” or “generation misread”.
Compare
Reading the trace
| What the trace shows | Classification |
|---|---|
| Correct chunk not retrieved, or ranked out | Retrieval failure |
| Correct chunk in the prompt, answer ignores or contradicts it | Generation failure |
| Correct chunk in the prompt, answer follows it, chunk is wrong or outdated | Source failure |
| No relevant chunk, yet a confident answer | Retrieval failure plus a missing abstention rule |
Ask in order: was the evidence retrieved, was it in the prompt, did the answer follow it, was the evidence right?
Worked example
Worked example: a trace, read step by step
Illustrative trace for the question “Can I return a sale jacket?”
| Field | Value |
|---|---|
| Retrieved chunk c-12 (score 0.66) | “Our store opens at 9 am on weekdays.” |
| Retrieved chunk c-40 (score 0.58) | “Gift cards never expire.” |
| Chunk c-23 (score 0.55, rank 3, below the top-2 cut) | “Sale items cannot be returned.” |
| Final prompt contains | c-12 and c-40 only |
| Answer | “Yes, returns are accepted within 14 days.” |
- Was the evidence retrieved? Only as rank 3, and it was cut before the prompt.
- Was it in the prompt? No.
- Did the answer follow evidence? It had none, and it still answered confidently.
- Verdict: retrieval failure (the right chunk was ranked out) plus a missing abstention rule. Next moves: improve ranking or widen the cut, and add a “not in the context” fallback.
If c-23 had been in the prompt and the answer still said yes, the verdict would flip to generation failure.
Diagram
Measure each stage on its own
Ragas splits evaluation along the same stages, with its own reference-free metrics for the retriever’s context, the model’s faithful use of it and generation quality. Precision@k, MRR and abstention rate are standard measures you compute yourself.
Source[3] RAGAs: Automated Evaluation of Retrieval Augmented Generation
Math
Faithfulness as a fraction
faithfulness=total claimssupported claims| Symbol | Meaning |
|---|---|
| supported claims | Claims in the answer that the retrieved context supports |
| total claims | All claims found in the answer |
| faithfulness | A score from 0 to 1; higher means more of the answer is grounded |
The Ragas documentation computes it this way: break the response into claims, check each against the retrieved context, divide.
Example: an answer makes 4 claims and the context supports 3 of them, so faithfulness is 43=0.75. The unsupported one is your hallucination.
Source[4] Faithfulness
Concept
Golden set and abstention
- Golden set: a fixed list of questions with expected answers or gold passages, run on every change.
- Include questions the corpus cannot answer. The right behaviour is “I don’t know”.
- Abstention rate: how often the system declines, and whether declining was right.
- A golden set works like unit tests: fixing one question must not silently break ten others.
Evaluating only end to end hides which stage regressed.
Math
How much to trust a small gain
points per questionrough wobble=n100=np×(1−p)| Symbol | Meaning |
|---|---|
| n | Number of questions in the golden set |
| p | Share answered correctly (as a fraction) |
| points per question | Score change when exactly one question flips |
| rough wobble | A rule-of-thumb standard error if questions are treated as independent draws |
Worked with n=50 and 35 correct (p=0.70):
- One question =50100=2 points.
- Wobble =500.70×0.30=0.0042=0.065, about 6.5 points.
So a 2 to 4 point gain on 50 questions is one or two flips, well inside the wobble. Comparing two versions on the same questions is usually tighter than this rough figure, but the next step is the same: add questions, look at which ones changed and why, rerun.
Check yourself
Check: pick the safeguard
A team adds a reranker and expects fewer “confident but wrong” answers. On review, the wrong answers are mostly questions where the correct chunk never appears in the retrieved candidates. Why did reranking not help, and what should they look at instead?
Answer
A reranker only reorders the candidates it receives. If the correct chunk was never retrieved, there is nothing to promote. Look at retrieval recall at the candidate stage: chunking, hybrid search, filters, or a larger candidate pool.
Check yourself
Check: classify and measure
A trace shows the top-ranked chunk is a 2021 price list that the company replaced in 2023, the prompt contains it, and the answer quotes it correctly. A teammate wants to retune the prompt. Classify the failure, say why the prompt change would not help, and name a metric that would catch this on a golden set.
Answer
Source failure: the answer is faithful to a chunk that is out of date. Retuning the prompt cannot change what the source says; refresh or remove the stale document and add freshness metadata. A golden-set question whose gold answer is the current price would score the answer as incorrect even though faithfulness stays high, which is why faithfulness alone is not enough.
Summary
Recap
- RAG reduces hallucination; it does not eliminate it.
- Right context can be ignored, misread or blended with unsupported claims; the source can also be wrong.
- Mitigations: grounding instruction, citations, reranking, retrieval gate, verification. Each has a limit.
- Classify from the trace: retrieval, generation or source.
- Measure retrieval and generation separately on a golden set, and treat small gains on small sets as noise until confirmed.
References
References & Sources
Reduce hallucinations (opens in a new tab)
Anthropic2026Documentation
https://platform.claude.com/docs/en/test-and-evaluate/strengthen-guardrails/reduce-hallucinations
Used for Techniques such as permission to say 'I don't know', quote-first grounding and citation-based verification reduce hallucinations significantly but do not eliminate them; validate critical information.
Lost in the Middle: How Language Models Use Long Contexts (opens in a new tab)
Nelson F. Liu, Kevin Lin, John Hewitt, Ashwin Paranjape, et al.2023Transactions of the Association for Computational Linguistics (TACL)Paper
arXiv 2307.03172 (opens in a new tab)https://arxiv.org/abs/2307.03172
Used for Models use long inputs unevenly: performance is often highest when relevant information is at the start or end and lower in the middle.
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.
Keys: ← → move, Home End first and last, F full screen.