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.
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
| Symptom | Likely cause | Fix |
|---|---|---|
| Answer is in a document, but no chunk contains it whole | Bad parsing or chunking | Fix extraction; structure-aware chunks; add headings to chunks |
| Exact codes, names or acronyms are missed | Vector-only search | Add keyword search (hybrid) |
| Right chunk is in top 50 but not top 5 | Weak ranking | Add a reranker |
| Old version of a policy is retrieved | Stale index, no date filter | Delete removed docs; filter or boost by date |
| Short or vague queries ("and for contractors?") | Query lacks context | Rewrite the query using the chat history (lesson 3.4) |
Generation failures, and their fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| Adds facts not in the sources | Weak grounding rules; temperature too high | Stricter rules, citations per claim, temperature near 0 |
| Ignores the relevant chunk | Too much context; buried in the middle | Fewer, better chunks; best first |
| Refuses although the answer is there | Over-strict prompt; answer spread over chunks | Allow 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.
- 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).
- 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
Prompt-tweaking retrieval bugs
Error analysis
Check your understanding
Score 75% or more to master this lesson and earn XP. Answer first, then check.