When a retrieval-augmented generation (RAG) application returns irrelevant, incomplete, or unsupported answers, the failure may be in the query, filters, retrieval settings, reranker, context assembly, or generation prompt. This diagnostic workflow helps you isolate the failing stage, collect evidence, and improve RAG accuracy without changing several variables at once.
Overview
RAG systems usually follow a chain: ingest documents, split them into chunks, create embeddings, retrieve candidates, optionally rerank them, assemble context, and generate an answer. A weak result at the end does not prove that the language model is the problem. The application may never have retrieved the passage needed to answer the question.
Start by treating every response as an observable pipeline rather than a single model call. For each test question, record the normalized query, applied metadata filters, retrieved document IDs, similarity or relevance scores, reranked order, final context, prompt version, model, and answer citations. This retrieval audit makes it possible to distinguish a retrieval problem from a context or generation problem.
Use a small, stable evaluation set before making changes. Include direct questions, questions requiring multiple passages, questions with similar terminology, questions that should produce “not found,” and questions affected by metadata such as department, product, date, or access scope. Change one stage at a time and compare the same set after each change. For broader evaluation guidance, see LLM Evaluation Frameworks: How to Test Prompts for Accuracy, Safety, and Consistency.
| Symptom | Likely cause | First diagnostic |
|---|---|---|
| The answer says the information is unavailable | The required passage was not retrieved, or a filter excluded it | Search for the expected document without generation and inspect applied filters |
| The answer uses a related but incorrect topic | Query ambiguity, broad chunks, or weak ranking | Inspect the top candidates and compare their terms and metadata with the question |
| The answer contains only part of the policy or procedure | Small chunks, low retrieval depth, or missing neighboring context | Check whether the missing detail is in an adjacent chunk or another document |
| The retrieved passages are correct but the answer is wrong | Context assembly, prompt instructions, or generation failure | Log the exact final prompt and test it with a fixed context |
| Results change unexpectedly between identical requests | Query rewriting, mutable indexes, filters, or generation variability | Compare request payloads, index versions, and model settings |
Checklist by scenario
Scenario 1: Nothing relevant is retrieved
- Run the user’s query directly against the retrieval layer and save the top results.
- Confirm that the source document was ingested, parsed, and indexed successfully.
- Check whether formatting, OCR, tables, headers, or code were lost during extraction.
- Compare the user’s wording with the document’s terminology. Try a controlled query rewrite, but retain the original query for auditing.
- Test both semantic and lexical retrieval when the question contains product names, error codes, identifiers, or exact phrases.
- Review embedding-model compatibility. Documents and queries should be represented using the intended, compatible configuration.
If direct retrieval fails, do not begin by rewriting the answer prompt. Fix ingestion, indexing, query formulation, or search configuration first.
Scenario 2: Relevant content exists, but results are too broad
- Inspect chunk size and boundaries. A chunk that combines several unrelated topics can appear relevant while diluting the useful passage.
- Check overlap. Too little overlap can split definitions, qualifications, or step-by-step instructions across separate chunks.
- Increase candidate depth temporarily to determine whether the correct passage appears lower in the result set.
- Use metadata filters only when the filter values are reliable and mapped consistently.
- Add reranking when initial retrieval produces a plausible but poorly ordered candidate list. Evaluate whether the reranker improves ordering on your test set rather than assuming it will.
Scenario 3: Results are relevant but incomplete
- Check whether the answer requires multiple documents or neighboring chunks.
- Retrieve enough candidates to cover each part of the question, then deduplicate repeated passages.
- Preserve document titles, section headings, dates, and source identifiers in the context.
- Consider hierarchical retrieval: identify the relevant document or section first, then retrieve smaller passages within it.
- Ask the generation step to identify missing evidence and abstain when the supplied context does not support a conclusion.
Scenario 4: The context is correct, but the answer is wrong
- Log the final assembled context, not just the IDs returned by the vector database.
- Look for truncation caused by context limits, duplicated passages, or irrelevant content placed before the key evidence.
- Use explicit instructions to answer from the supplied sources, distinguish evidence from inference, and cite the supporting passage.
- Test the prompt with a fixed context and several model settings. If the same context produces inconsistent behavior, focus on generation and prompt design.
- Check for prompt injection or untrusted instructions inside retrieved documents. The Prompt Injection Defense checklist covers a separate threat-modeling workflow for this risk.
What to double-check
Metadata and permissions: Confirm that filters use the same spelling, types, time zones, and identifiers as the indexed records. A valid query can return nothing when a date is stored as text in one system and as a timestamp in another. Also verify that authorization filtering happens consistently; never remove access controls merely to improve recall.
Chunking: Preserve semantic units such as a heading with its explanation, a question with its answer, or a procedure with its conditions and exceptions. Test chunk changes against questions that depend on boundaries, not only simple lookups.
Retrieval depth: A small top-k may be fast but insufficient for multi-part questions. A very large top-k can introduce noise and consume context. Measure the trade-off with a fixed evaluation set instead of selecting a value by intuition alone.
Reranking: Reranking can improve the order of retrieved candidates, but it cannot recover a passage that was never retrieved. Compare first-stage recall and final-context quality separately.
Citations: A citation is useful only if it supports the specific claim. Verify that cited text is present in the final context and that citations are not being attached after generation without evidence checks.
Prompt and context limits: Long contexts may be truncated or may bury the relevant passage. See LLM Context Window Management for practical ways to manage truncation, compression, and memory.
Common mistakes
- Tuning the model before measuring retrieval: A stronger generator cannot reliably answer from absent evidence.
- Changing several settings at once: Simultaneously changing chunking, embeddings, top-k, reranking, and prompts prevents useful attribution.
- Evaluating only fluent answers: A confident response can still be unsupported. Score retrieval relevance, completeness, groundedness, and abstention separately.
- Using filters as an afterthought: A metadata filter can silently remove the correct source. Log both the filter request and the records it excludes.
- Assuming semantic search handles exact identifiers: Error codes, version numbers, names, and legal phrases often benefit from lexical or hybrid matching.
- Ignoring document freshness: Duplicate or outdated documents can outrank the current source. Store effective dates and source versions where they matter.
- Trusting a single test question: Build a compact regression set and retain failures as new test cases.
When to revisit
Run this checklist whenever users report a new failure pattern, a knowledge base is added or replaced, chunking or embedding settings change, retrieval APIs or reranking components change, or a model and prompt are updated. It is also useful before a seasonal planning cycle when documents, policies, catalogs, or operational procedures are refreshed.
Keep a retrieval audit worksheet with these fields: question ID, expected source, query and rewrite, filters, index version, retrieved IDs and scores, reranked IDs, final context, answer, citations, failure category, and next experiment. Review the worksheet after each configuration change and preserve a known-good baseline.
For a practical next pass, select ten to twenty representative questions, run them through the complete pipeline, and classify each failure as query, ingestion, filtering, retrieval depth, reranking, context assembly, citation, or generation. Fix the earliest failing stage, rerun the same questions, and only then move to the next stage. Once the results are stable, include the RAG checks in your wider AI application deployment checklist and document the chosen configuration, evaluation set, and rollback plan.