Lesson 3.3 · 8 min read · about 55 min to master at a very slow pace

Why RAG Fails: A Debugging Guide

Every wrong RAG answer is either a retrieval failure or a generation failure. A step-by-step method to tell which, the seven most common root causes, and what fixes each one.

Not startedJump to quiz

First question: was the answer in the context?

For a wrong answer, open the log and read the chunks that were sent to the model.

  • The answer was not in the chunks → a retrieval failure. Changing the prompt or the model will not help.
  • The answer was in the chunks, but the reply is wrong → a generation failure. Retrieval is fine; look at the prompt, the context layout or the model.

This one split halves the search space and is the habit that separates engineers who fix RAG systems from those who keep rewording the prompt.

Retrieval failures, and their fixes

SymptomLikely causeFix
Answer is in a document, but no chunk contains it wholeBad parsing or chunkingFix extraction; structure-aware chunks; add headings to chunks
Exact codes, names or acronyms are missedVector-only searchAdd keyword search (hybrid)
Right chunk is in top 50 but not top 5Weak rankingAdd a reranker
Old version of a policy is retrievedStale index, no date filterDelete removed docs; filter or boost by date
Short or vague queries ("and for contractors?")Query lacks contextRewrite the query using the chat history (lesson 3.4)

Generation failures, and their fixes

SymptomLikely causeFix
Adds facts not in the sourcesWeak grounding rules; temperature too highStricter rules, citations per claim, temperature near 0
Ignores the relevant chunkToo much context; buried in the middleFewer, better chunks; best first
Refuses although the answer is thereOver-strict prompt; answer spread over chunksAllow partial answers; test with multi-chunk questions

A real-looking case

A staff assistant answers "How many days of paid leave do new employees get?" with "25 days". The handbook says 20 days in the first year, 25 after.

  1. Check the context: the sent chunk contains the table row "After 12 months: 25 days" but the row "First year: 20 days" was in the previous chunk. → Retrieval (chunking split the table).
  2. Fix: chunk tables whole, with their header. Add this question to the eval set so it never regresses.

Error analysis beats intuition

Read 30–50 failed answers, label each with a root cause from the tables above, and count. Fix the biggest bucket first. This takes an afternoon and usually points to one or two fixes that matter.

Stuck? Common doubts

Questions real learners asked while studying this lesson. They stay closed so they don't spoil your own thinking: open only the ones you need.

First passWhat if the logs don't show which chunks were sent?

Then fix logging first. For every request, store the query, any rewritten query, the retrieved chunk IDs with scores, the final prompt (or a reference to it), the answer and the latency. Without it you can only guess. Lesson 6.4 covers tracing in production.

Going deeperCan a stronger model fix retrieval failures?

No. If the evidence was never sent, the model can only refuse or guess. A stronger model may guess more convincingly, which is worse. Stronger models help with generation failures, such as combining evidence from several chunks.

Cheatsheet

The first debugging question

Was the answer in the retrieved context? No → retrieval failure. Yes → generation failure.

Prompt-tweaking retrieval bugs

If the evidence was never retrieved, no prompt or model change can fix the answer.

Error analysis

Label 30–50 failures by root cause, count, fix the biggest bucket, add the cases to the eval set.

See every cheatsheet by category →

Check your understanding

Score 75% or more to master this lesson and earn XP. Answer first, then check.

Q1diagnoseA wrong answer's log shows the correct fact was not in any of the chunks sent. What kind of failure is this?
Q2diagnoseThe correct chunk was sent first in the context, yet the answer adds a figure that appears in no source. Where is the problem?
Q3applyUsers ask about error codes like "E-4471" and the system keeps returning chunks about "E-4417". What is the best fix?
Q4conceptWhat is error analysis in a RAG project?
Q5diagnose"How many leave days do new staff get?" returns 25 instead of 20. The table row for the first year was in the previous chunk. What is the root cause?