Slides · Retrieval-augmented generation

RAG evaluation and hallucination

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.

Source1 Reduce hallucinations

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 answersFailureWhy
“Returns are accepted within 30 days.”Ignores the contextAnswered from memory of other shops
“All items, including sale items, can be returned within 14 days.”Misreads the contextDropped the sale-item exception
“Standard returns within 14 days, and a prepaid label is provided.”Blends in an unsupported claimThe 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.

Source2 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

TechniqueWhat it doesLimit
Grounding instructionTells the model to answer only from context and say it does not know otherwiseAn instruction, not a guarantee; test its wording for loopholes
CitationsEach claim points to a chunk, so unsupported claims showA citation can point at a chunk that does not say it; check accuracy, not presence
RerankingBest evidence first, weak chunks outCannot fix evidence that was never retrieved
Retrieval gateRefuse when the best score is too lowScores are not comparable across models; calibrate on labelled data
Verification passA second pass checks claims against the contextExtra 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.

Source1 Reduce hallucinations

Diagram

How the mitigations fit together

Diagram: After retrieval, a score gate refuses low-confidence questions.

no

yes

no

yes

Question

Retrieve chunks

Top score above threshold?

Say: not in the docs

Rerank

Generate with citations

Claims trace to cited chunks?

Flag, regenerate or escalate

Return answer and citations

Diagram summary: After retrieval, a score gate refuses low-confidence questions. Otherwise chunks are reranked and the answer is generated with citations, then checked: claims that do not trace to cited chunks are flagged, regenerated or escalated, and traceable ones are returned with their citations.

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.

QuestionBest chunk scoreGate at 0.50Right behaviourOutcome
Answerable, full sentence0.71PassAnswerCorrect
Not in the docs at all0.55PassRefuseWrong answer
Answerable, two-word keyword query0.48RefuseAnswerWrong 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:

  1. the question,
  2. the retrieved chunks, with ids and scores,
  3. the final prompt sent to the model,
  4. 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 showsClassification
Correct chunk not retrieved, or ranked outRetrieval failure
Correct chunk in the prompt, answer ignores or contradicts itGeneration failure
Correct chunk in the prompt, answer follows it, chunk is wrong or outdatedSource failure
No relevant chunk, yet a confident answerRetrieval 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?”

FieldValue
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 containsc-12 and c-40 only
Answer“Yes, returns are accepted within 14 days.”
  1. Was the evidence retrieved? Only as rank 3, and it was cut before the prompt.
  2. Was it in the prompt? No.
  3. Did the answer follow evidence? It had none, and it still answered confidently.
  4. 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

Diagram: Retrieval is scored with precision@k, recall@k and MRR, generation with faithfulness and answer relevance, and the final behaviour with the...

precision@k, recall@k, MRR

faithfulness, answer relevance

abstention rate

Question

Retrieve

Generate

Answer

Retrieval metrics

Generation metrics

Behaviour metrics

Diagram summary: Retrieval is scored with precision@k, recall@k and MRR, generation with faithfulness and answer relevance, and the final behaviour with the abstention rate on questions the corpus cannot answer. Scoring them separately shows which stage to fix.

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.

Source3 RAGAs: Automated Evaluation of Retrieval Augmented Generation

Math

Faithfulness as a fraction

faithfulness=supported claimstotal claims\text{faithfulness} = \frac{\text{supported claims}}{\text{total claims}}
SymbolMeaning
supported claims\text{supported claims}Claims in the answer that the retrieved context supports
total claims\text{total claims}All claims found in the answer
faithfulness\text{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 34=0.75\frac{3}{4} = 0.75. The unsupported one is your hallucination.

Source4 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 question=100nrough wobble=p×(1−p)n\begin{aligned} \text{points per question} &= \frac{100}{n} \\ \text{rough wobble} &= \sqrt{\frac{p \times (1 - p)}{n}} \end{aligned}
SymbolMeaning
nnNumber of questions in the golden set
ppShare answered correctly (as a fraction)
points per question\text{points per question}Score change when exactly one question flips
rough wobble\text{rough wobble}A rule-of-thumb standard error if questions are treated as independent draws

Worked with n=50n = 50 and 35 correct (p=0.70p = 0.70):

  • One question =10050=2= \frac{100}{50} = 2 points.
  • Wobble =0.70×0.3050=0.0042=0.065= \sqrt{\dfrac{0.70 \times 0.30}{50}} = \sqrt{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

  1. Reduce hallucinations (opens in a new tab)

    Anthropic2026Documentation

    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.

  2. 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

    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.

  3. 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

    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.

  4. Faithfulness (opens in a new tab)

    Ragas2026Documentation

    Used for Faithfulness is the number of response claims supported by the retrieved context divided by the total number of claims.