Retrieval Quality: How to Debug Why Your RAG System Returns the Wrong Documents

Your RAG chatbot answered a question about the refund policy by quoting an old pricing page. The right document exists in your corpus, but the retriever never surfaced it. That is a retrieval quality problem, not a model problem, and swapping in a bigger language model will not fix it. This guide walks through how to debug rag retrieval quality step by step, starting with the cheapest checks and moving toward the ones that cost real engineering time. Each section names a concrete symptom, the test that confirms it, and the fix.

Measure rag retrieval quality before you change anything

Debugging without a baseline turns into guesswork. Before you touch chunk size or swap embedding models, build a small test set: 20 to 30 real questions your users actually ask, each paired with the document that should answer it. Run each question through your retriever and record whether the right document lands in the top 5 results. That hit rate is your baseline. If it is already above 90 percent, your retrieval is probably fine and the problem sits in the prompt or the generation step. If it sits at 60 percent, you have a retrieval problem worth fixing, and now you can measure whether each change helps or hurts. Keep the test set in a plain file and rerun it after every change. A shared evaluation setup also makes it easier to compare approaches, and RAG evaluation frameworks such as RAGAS give you a ready-made structure for scoring retrieval and answer quality together.

Check chunking first: the most common culprit

Most retrieval failures start at chunking. If a chunk is too large, it mixes several topics and its embedding becomes a blur that matches nothing well. If a chunk is too small, it loses the context that makes it relevant, so a paragraph about refunds can look identical to one about cancellations. A common starting point is chunks of 400 to 800 tokens with 10 to 20 percent overlap, then adjust based on your test set. Splitting mid-sentence or mid-table is a frequent source of silent failures: the answer is in the index, but the sentence that proves it got cut in half. Different rag chunking strategies suit different content: fixed-size chunks work for uniform prose, recursive splitting keeps headings and paragraphs intact, and semantic chunking groups sentences by meaning. Pick one, measure, then change one variable at a time. Also check that your chunker handles your real formats. PDFs with two-column layouts and tables often extract in the wrong order, and a chunker that was tested on clean Markdown may mangle them.

Look at the query, not just the documents

Sometimes the documents are fine and the query is the problem. Users ask short, vague questions: “refund?” carries almost no signal for an embedding model to match against. Compare the query embedding with the embedding of the document that should match. If they sit far apart in vector space, the query needs help before retrieval runs. Common fixes are query expansion (add synonyms or related terms), hypothetical document embedding (ask the model to write a short ideal answer, then search with that), or simply rewriting the user’s question into a fuller sentence. Also check for vocabulary mismatch: your docs say “reimbursement” while users say “money back.” If the words never overlap, pure vector search may still catch the meaning, but a keyword component will not. Log the raw queries your users send. The patterns in real traffic tell you more about what to fix than any synthetic test set.

Add hybrid search when vectors alone miss

Vector search understands meaning but ignores exact terms. Keyword search does the opposite. When your failures involve product names, error codes, version numbers, or part numbers, vectors alone will keep missing. Hybrid search runs both and merges the results, usually with a method called reciprocal rank fusion. A typical setup retrieves the top 20 candidates from each method, merges them, and keeps the top 10. The exact split is worth tuning against your test set, but the point is that the two methods cover each other’s blind spots. Watch for one method dominating the merged list: if the vector results always win, the keyword side adds nothing, and you may need to normalize scores before merging. Most vector databases now support hybrid search natively, so this is often a configuration change rather than a rebuild.

Rerank the top results before handing them to the model

Retrieval is a two-stage problem: recall, then precision. Your first pass only needs to find the right document somewhere in the top 20. A reranker then reads each candidate alongside the query and reorders them by actual relevance. Cross-encoder reranker models are slower than embedding search, but they only run on a small candidate set, so the cost stays manageable. The practical effect is that a document sitting at rank 14 can move to rank 2, which matters because most RAG pipelines only pass the top 3 to 5 chunks to the language model. If your test set shows the right document usually appears in the top 20 but rarely in the top 3, reranking is the fix to try first. Measure latency after adding it: reranking adds tens of milliseconds per query for small candidate sets, which most interactive apps can absorb.

Check the index itself: stale, duplicate, and misfiltered documents

Before blaming the search algorithm, verify what is actually in the index. Query the vector store directly for a document you know should be there. Common surprises: the document was never ingested because the pipeline skipped a file type, an old version replaced the new one, or a metadata filter silently excluded half the corpus. Duplicates are another quiet killer. If the same content appears five times with slightly different wording, it crowds out other results and the model reads the same answer five times. Deduplicate at ingest time. Also confirm your filters do what you think: a filter on “department = support” that your documents never set will return nothing, and a date filter with the wrong timezone can hide recent updates. A quick count of documents per source and per date range usually reveals these problems in minutes.

When retrieval is fine and the answer is still wrong

Sometimes the retriever returns the right document and the answer is still wrong. Check what the model actually received: log the exact context passed in the prompt. A chunk that ranks well can still be truncated mid-sentence, or the prompt may bury the relevant passage under several irrelevant ones. The model tends to weight the first and last chunks most, so order matters. If the answer contradicts the retrieved text, the problem is grounding, not retrieval: tighten the prompt to require answers from the provided context, and review how retrieval-augmented generation works end to end before adding more documents. Adding more context rarely fixes a model that ignores the context it already has.

A quick symptom-to-fix map

Symptom Likely cause First fix to try
Right document never in top 20 Chunking or ingestion Check chunk boundaries and index contents
Right document at rank 10 to 20 Ranking precision Add a reranker
Exact terms missed (codes, names) Vector-only search Switch on hybrid search
Short user queries fail Weak query signal Query rewriting or expansion
Stale answers Old documents in the index Rebuild the index and deduplicate
Right context, wrong answer Grounding or prompt Log the prompt and tighten instructions

Debug in order: measure first, then chunking, then the query, then hybrid search and reranking, then the index itself. Most retrieval problems turn out to be one of those five, and the test set you built in the first step tells you which one within an hour. Fix one variable at a time, rerun the test set, and keep the change only if the hit rate moves.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.