Cheat sheet
RAG troubleshooting cheat sheet
Why a RAG system gives wrong answers, and what to check first: wrong document, right document but wrong answer, missing recent data, slow queries, with fixes.
Bookmark
Bookmarks are kept in your free account, so you can find this page again on any device.
Sign in to bookmarkOn this page
When a RAG system answers badly, look at the chunks it retrieved for the failing question. If the right chunk is missing, fix retrieval: chunking, search, filters or freshness. If it is there and the answer is still wrong, fix the prompt, the context order or the model. Measure every fix on the same golden set.
First check: which half failed
| You see | It means | Go to |
|---|---|---|
| The right chunk is not in the top results | Retrieval failure | Wrong or missing documents |
| The right chunk is retrieved but the answer ignores or contradicts it | Generation failure | Right document, wrong answer |
| The answer is right but cites the wrong source | Citation mapping | Right document, wrong answer |
| Results are right but arrive slowly | Latency | Slow or expensive |
Log the question, the retrieved chunk IDs with scores, and the final prompt for every request. Without that log you are guessing.
Wrong or missing documents
| Symptom | Likely cause | Check | Fix |
|---|---|---|---|
| Exact names, codes or error IDs are not found | Vector search alone misses rare exact terms | Search the term with full-text search | Add keyword search and merge results (hybrid search) |
| The answer is split across chunks, each too vague to match | Chunks too small or cut mid-section | Read the chunks for one document end to end | Chunk by headings; add overlap |
| Chunks match but lack the subject (“it increased 3%”) | The chunk lost its document context | Read a top chunk on its own: is it clear what it is about? | Prepend a title or a short context line to each chunk before embedding |
A filtered query returns fewer rows than LIMIT |
The filter is applied after an approximate index scan | Run the query with and without the filter | Turn on iterative scans (hnsw.iterative_scan = relaxed_order, pgvector 0.8.0+), or index the filter column |
| Recall dropped after adding an HNSW or IVFFlat index | Approximate search trades recall for speed | Compare with an exact search on a sample | Raise hnsw.ef_search (default 40) or ivfflat.probes (default 1) |
| Near-duplicate chunks fill the top results | The same text was ingested several times | Count chunks by content hash | Deduplicate at ingestion |
| Queries in one language miss documents in another | The embedding model is weak across languages | Test a few translated pairs | Use a multilingual embedding model, or translate the query |
Right document, wrong answer
| Symptom | Likely cause | Check | Fix |
|---|---|---|---|
| The answer adds facts that are in no chunk | The model fills gaps from its own knowledge | Score faithfulness on the failing cases | Tell it to answer only from the context and to say when the context is silent |
| The key fact sits in the middle of a long context and gets missed | Models use the start and end of long contexts best | Move the right chunk to the top and re-run | Pass fewer, better-ranked chunks; put the best first |
| The answer mixes two products or versions | Similar chunks from different sources | Check the sources of the retrieved chunks | Filter by product or version metadata before ranking |
| It cites chunk 3 for a fact from chunk 5 | Chunk IDs are lost or renumbered in the prompt | Print the prompt the model received | Give each chunk a stable ID and ask for it in the answer |
| Fine on short questions, poor on multi-part ones | One search cannot cover several sub-questions | Split a failing question by hand and retrieve each part | Decompose the query, or let an agent search more than once (agentic RAG) |
Missing recent data
| Symptom | Likely cause | Check | Fix |
|---|---|---|---|
| Last week’s documents never appear | Ingestion did not run or failed quietly | Compare source document counts with indexed ones | Schedule ingestion and alert on failures |
| An edited document returns its old text | Old chunks were not deleted on update | Search for a sentence you removed | Delete by document ID before re-inserting |
| New documents rank below old ones | Nothing in ranking knows about dates | Look at the dates of the top results | Filter or boost by date where the question is about “latest” |
| Results changed after a model upgrade | Old and new embeddings are mixed | Check the embedding model recorded per row | Re-embed everything with one model; store the model name per row |
Slow or expensive
| Symptom | Likely cause | Check | Fix |
|---|---|---|---|
| Vector queries scan the whole table | No approximate index, or the planner skips it | EXPLAIN ANALYZE the query |
Add an HNSW index; keep ORDER BY embedding <=> ... LIMIT in the query |
| A reranker doubles the response time | Reranking too many candidates | Time each stage separately | Rerank 20 to 50 candidates, not hundreds |
| Prompt costs grow with every release | More chunks added “to be safe” | Tokens per request in your traces | Cut k, and measure whether quality held |
| Tenants slow each other down | One shared approximate index | Recall and latency per tenant | Partial indexes or partitions per tenant |
Measure before and after
| Metric | Tells you | Where |
|---|---|---|
| Hit rate at k | Whether the right chunk is in the top k | Your golden set, no judge needed |
| Context precision and recall | How much of what you retrieved was relevant, and how much relevant text you found | Ragas, or an LLM judge |
| Faithfulness | Whether the answer stays within the retrieved context | Ragas, promptfoo or DeepEval |
| Answer correctness | Whether the final answer matches the expected one | Golden set with reference answers |
Anthropic reported that adding context to chunks, plus keyword search and a reranker, cut its top-20 retrieval failure rate from 5.7% to 1.9% on its own test sets. Treat that as a reason to try the techniques, then measure on your data.
Common mistakes
| Mistake | Fix |
|---|---|
| Changing chunking, embeddings and prompt in one go | Change one thing per run, on the same golden set |
| Judging by a handful of questions you remember | Keep 30 to 50 labelled questions and run them all |
Raising k to fix every miss |
It hides retrieval problems and costs tokens; fix ranking instead |
| Building RAG for a corpus that fits in the prompt | Under about 200,000 tokens, try putting it all in the prompt with caching first |
Check your fix
Run the golden set before and after, and compare hit rate and faithfulness per question, not only the average. The golden-set evaluation workflow sets this up in CI. For the mechanics behind each fix, see hybrid search and reranking, chunking strategies and embeddings and vector search. If RAG is new to you, start with what RAG is.
Check your understanding
RAG troubleshooting quiz
Telling retrieval from generation failures, exact-term misses, lost chunk context, filtered and approximate search, long contexts, stale data, cost, and measuring a fix.
8 questions · pass mark 70%
Review
Checked against
Related
- RAG fundamentals: retrieval before generation
What RAG is and how retrieval-augmented generation works, when it beats long context or fine-tuning, and a minimal working pipeline in about 80 lines of Python.
- Evaluate RAG answers with a golden dataset
Set up RAG evaluation with a golden dataset and promptfoo: score retrieval, correctness and grounding for every question, and fail CI when answer quality drops.
- Hybrid search and reranking in Postgres
Combine Postgres full-text search and pgvector with reciprocal rank fusion in one SQL query, rerank the top results with a cross-encoder, and measure the gain.
- Chunking strategies for RAG, tested
Compare fixed-size, heading-based and semantic chunking on the same documents and questions, measure retrieval hit rate, and pick a strategy with evidence.
- Context precision and recall
RAG retrieval metrics: precision is the share of retrieved chunks that are relevant, recall the share of needed facts found.