Retrieval
RAG failure modes and debugging
Five ways a RAG answer goes wrong, how to tell them apart from one failing trace, and the first fix for each.
When a RAG answer is wrong, the fix depends on the stage that failed. A missed chunk needs better retrieval. A right chunk the model ignored needs a better prompt. Changing the wrong stage wastes weeks. This page gives you a taxonomy and a debugging order to find the stage quickly.
The big idea
Each failure leaves a different trail in the trace: the question, the retrieved chunk IDs and the answer. Read those three things before you change anything.
| Failure | Symptom | First fixes |
|---|---|---|
| Retrieval miss | The answer is not in the top-k at all | Chunking, hybrid search, query rewrite, larger k, a better embedder |
| Wrong chunk | A near-miss topic, not the fact | Reranker, metadata filters, contextual chunking |
| Context ignored | The right chunk is retrieved, but the model does not use it | Fewer and better chunks, clearer instructions |
| Fake citation | Cites [3] for a claim no source makes | Parse citations, reject missing IDs, ask for quotes |
| Stale or unauthorized | Old content, or another tenant's data | Fix the sync, filter access in the retrieval query |
A medical triage table is a useful picture: symptoms point to the likely cause, and the first test is chosen by the symptom. The analogy stops at one point: in RAG, the same symptom ("wrong answer") can come from any row, so you need the trace to choose.
Walking through a real debugging session
Symptom: users say the bot invents refund windows. Follow the order:
- Pull one failing trace. Read the question, the retrieved chunk IDs and the answer.
- Check whether the gold policy chunk is in the top-k. If not, it is a retrieval miss. Look at chunking, hybrid search and k.
- If it is there, read the chunk. If the chunk is a partial sentence that cuts off the window, the problem is chunking.
- If the chunk is correct and the model ignored it, the prompt is weak, too many chunks compete, or the temperature is too high.
- If the model cited
[4]but only three sources were sent, the failure is a fake citation. Tighten the code that checks citations.
This five-minute order beats speculative changes. It also keeps you from reaching for agents before the basics work.
Measure each stage
Score retrieval and generation separately:
- Retrieval: recall at 5, on a labeled set of questions with known source chunks. Many internal document bots aim for 0.8 to 0.9 before they add polish.
- Generation: whether the answer is faithful to the retrieved sources, and whether it refuses when the sources are silent.
A perfect generator cannot recover from a miss. A perfect retriever still needs a faithful reader.
Important
Log retrieved chunk IDs and scores with every answer. Without them, every failure looks like a model problem.
Common mistakes
- Tuning the prompt first. Most "model" bugs are retrieval or parsing bugs.
- Changing several things at once. You cannot tell which change helped. Change one stage at a time.
- Scoring only the final answer. It hides which stage failed.
Check yourself
- A user gets a wrong refund window, and the correct policy chunk is not in the top 5. Which stage failed? Retrieval. Fix chunking, search or k before the prompt.
- The right chunk is in the top 5, but the answer ignores it. What do you change first? The prompt and the number of competing chunks, then the temperature.
Key takeaways
- Read the trace first: question, chunk IDs, answer.
- Match the symptom to one failure type before you change anything.
- Measure retrieval recall and generation faithfulness separately.
- Fix stages in order: retrieval, then the prompt, then the citation checks.
Further learning
Return to the RAG hub for the pipeline overview, or read the wider evals page for how to build the labeled set this debugging needs.
Related
Retrieval-augmented generation
The core RAG pipeline: ingest, chunk, embed, retrieve, generate with citations.
Grounded answers with citations
The query-time path of RAG, from question to top-k chunks to a grounded prompt that refuses when evidence is missing and cites sources that code can check.
Evaluating LLM apps
A fixed set of inputs plus a way to score outputs, so you can tell whether a change helped.