RAG and Knowledge Grounding
Retrieval-Augmented Generation is the most powerful architectural intervention against hallucination: it shifts the model from trying to recall facts to reading and citing facts. This lesson explains how it works, where it still fails, and how to measure faithfulness.
Why RAG Reduces Hallucination
From Lesson 3: hallucination often occurs because the model does not have the correct fact in its parametric knowledge, so it generates a plausible-sounding token sequence instead. RAG addresses this at the root: rather than asking the model to recall a fact from training, it supplies the fact directly in the context window, then asks the model to read and synthesize what it was given.
This shifts the problem from "recall from uncertain training memory" to "read and faithfully report from a document you have in front of you." The latter is a task LLMs perform far more reliably than the former.
| Task structure | Hallucination source | RAG effect |
|---|---|---|
| Open-domain Q&A (no RAG) | Model recall from training data | N/A |
| Closed-domain Q&A with RAG | Faithfulness to retrieved chunk | Shifts problem; reduces factual hallucination significantly |
| Reasoning tasks | Logic errors | Minimal effect; reasoning hallucination is not a retrieval problem |
The Retrieval-Faithfulness Tension
Even with retrieved context in the window, models can still hallucinate. This is the retrieval-faithfulness problem: the model was supplied with the correct information but generated output that does not faithfully represent it. This happens for several reasons:
- Lost-in-the-middle effect: If the relevant chunk is buried in the middle of a long context, the model may under-attend to it. (See Lesson 3.)
- Parametric override: When the retrieved document conflicts with what the model "knows" from training, the model sometimes favors its parametric knowledge over the context. This is more common when the document says something surprising or counter-intuitive.
- Synthesis errors: When asked to synthesize across multiple retrieved chunks, models may blend or confuse information from different chunks, producing a hallucinated synthesis.
- Incomplete retrieval: If the retrieval step does not surface the right chunk, the model answers without the needed fact, and may hallucinate to fill the gap rather than acknowledging the limit.
Chunking Strategies for Faithfulness
The way you split documents into chunks has a direct effect on hallucination rate in RAG systems. Poorly chunked documents create retrieval gaps and synthesis problems.
- Semantic chunking over fixed-size chunking. Splitting at sentence or paragraph boundaries preserves context that fixed-character splits break. A fact that is spread across two 512-character chunks will not be retrieved as a unit; split at the boundary of the relevant fact, not at a character count.
- Overlap windows. Adding a 10-20% overlap between adjacent chunks ensures that facts near chunk boundaries appear in at least one complete chunk. Without overlap, boundary facts are the most likely to be missed by retrieval.
- Hierarchical chunking. For long documents, maintain both a document-level summary chunk and paragraph-level detail chunks. Use the summary for relevance routing, the detail chunks for faithful answer generation.
- Metadata tagging. Add source document name, section header, and page number to each chunk. Require the model to cite chunk metadata in its answer. This makes faithfulness auditable.
Citation-Forcing Patterns
The strongest RAG anti-hallucination prompt pattern is citation forcing: require the model to cite the specific chunk that supports each claim in its answer. Uncited claims are flagged as potentially hallucinated.
"You will be given retrieved document chunks labeled [Source 1], [Source 2], etc. Answer the user's question using only information from these chunks. For every claim you make, cite the source in brackets immediately after the claim, e.g. 'The effective date is January 1, 2026 [Source 2].' If no source supports a claim, do not make it. If the sources do not contain enough information to answer the question, say so explicitly."
This pattern achieves three things: it forces attribution, it creates an auditable output, and it gives the model a clear instruction for what to do when it lacks information.
Faithfulness Evaluation Metrics
Faithfulness evaluation measures how well the model's output is supported by the retrieved context. The field has converged on a set of metrics for this assessment:
| Metric | What it measures | How to compute |
|---|---|---|
| Faithfulness | Fraction of claims in the answer that are supported by the retrieved context | Decompose answer into claims; check each against context (manually or with LLM-as-judge) |
| Answer relevance | Whether the answer addresses the question (not accuracy, just relevance) | LLM-as-judge: "Does this answer the question?" |
| Context recall | Whether the retrieved chunks contain the information needed to answer | Compare answer to known reference; check if supporting facts were in retrieved chunks |
| Context precision | How much of the retrieved context was relevant (not noise) | Fraction of retrieved chunks that contributed to the answer |
When RAG Still Does Not Help
RAG is not a universal solution. Three categories of hallucination are largely unaffected by retrieval:
- Reasoning hallucinations: RAG provides facts, not reasoning. If the model makes a logical error with the correctly-retrieved facts, RAG cannot prevent it. Use chain-of-thought prompting (Lesson 5) for reasoning tasks.
- Synthesis hallucinations: When the answer requires combining information from many chunks, the synthesis step itself can introduce errors. Keep synthesis tasks narrow: fewer sources, more focused questions.
- Out-of-distribution queries: If the user's question is not well-served by any retrieved chunk, the model may answer from parametric memory rather than acknowledging the retrieval gap. Add explicit "no relevant information found" handling to your RAG pipeline.
Ready to Go Deeper?
Live instructor-led courses from our partners. Affiliate disclosure.
AI & ML Courses - 30% Off
Live instructor-led AI, machine learning, data science, and cloud courses for working professionals. Use code Limited30 at checkout.
EdurekaDataCamp - AI & Data Science
Hands-on Python, machine learning, and AI courses with interactive exercises and real projects.
DataCampedX - Top AI Courses
University-level AI courses from MIT, Harvard, Stanford. Earn certificates that employers recognize.
edX