Debugging Common RAG Failure Modes

A step-by-step method to find out whether retrieval or generation is at fault.

Last Updated: 27, Nov 2026

Search Tutorials

--Ads--

Appendix · Lesson 1 of 4 · Beginner

Debugging Common RAG Failure Modes

A step-by-step method to find out whether retrieval or generation is at fault.

When a RAG system gives a wrong answer, the instinct is to change the prompt. Often the prompt is not the problem. A wrong answer can start anywhere in the pipeline, and fixing the wrong stage wastes time or makes things worse. This lesson gives you a systematic method: trace the answer backwards, stage by stage, until you find where the evidence was lost.

Flowchart: check whether the answer is in the documents, whether the right chunk was retrieved, whether it reached the prompt, and whether the answer is faithful to it; each 'no' points to a category of problem.
Figure 1. Walk the pipeline backwards to find the stage that failed.

The four questions

  1. Is the answer in the indexed documents at all? Search the raw extracted text, not the vector index. If it is missing, no retrieval technique can help: the source document is missing, failed to parse, or the index is stale.
  2. Was the right chunk retrieved? Search with a large k (50) and find the rank of the chunk containing the answer. If it is not in the top 50, it is a retrieval problem.
  3. Did it reach the final prompt? If the chunk was at rank 12 but you send the top 5, or a reranker or threshold dropped it, it is a post-retrieval problem.
  4. Is the answer faithful to it? If the right chunk was in the prompt and the answer is still wrong, the problem is generation: prompt, conflicting sources, or reasoning.

A debugging helper

This function answers the four questions automatically for one question and an evidence phrase that should appear in the correct source.

debug_rag.py
def norm(s: str) -> str:
    return " ".join(s.lower().split())

def debug_question(question: str, evidence: str, raw_docs: dict[str, str], chunks: list[dict],
                   search, build_prompt, answer: str, final_k: int = 5) -> None:
    ev = norm(evidence)

    # 1. In the source text?
    in_docs = [name for name, text in raw_docs.items() if ev in norm(text)]
    print("1. Evidence in documents:", in_docs or "NO -> content gap or parsing failure")
    if not in_docs:
        return

    # 1b. In the chunks? (catches evidence split across a chunk boundary)
    in_chunks = [c["id"] for c in chunks if ev in norm(c["text"])]
    print("   Evidence in chunks:   ", in_chunks or "NO -> split across chunks; check chunking/overlap")

    # 2. Retrieved?
    hits = search(question, k=50)
    rank = next((r for r, h in enumerate(hits, start=1) if h.id in in_chunks), None)
    print("2. Rank of evidence chunk:", rank or "not in top 50 -> retrieval problem")
    if rank:
        print("   Top 3 instead:", [(h.id, round(h.score, 3)) for h in hits[:3]])

    # 3. In the prompt?
    prompt = build_prompt(question, hits[:final_k])
    print("3. Evidence in final prompt:", ev in norm(prompt))

    # 4. Faithful?
    print("4. Answer:", answer[:300])
    print("   (check faithfulness with the generation-metrics judge if step 3 is True)")

Common failures and fixes

SymptomLikely causeFixLesson
"I don't know" for documented factsText not extracted (scans, tables)Better parser, OCR or vision modelParsing
Outdated answersIndex not synced; old versions indexedIncremental sync, archive old versionsRe-indexing
Half an answerEvidence split across chunksOverlap, structure-aware or parent-child chunkingParent-child
Fails on codes, names, numbersDense-only retrievalHybrid searchHybrid search
Fails on casual or vague questionsVocabulary mismatchQuery rewriting, multi-query, HyDERewriting
Follow-ups fail in chatPronouns in the search queryQuery condensingCondensing
Right chunk at rank 8, k = 5Weak rankingReranker, retrieve widerReranking
Chunk from the wrong product or yearMissing context in chunkContextual headers, metadata filtersContextual retrieval
Answer ignores the provided sourceWeak grounding instructionsPrompt with reasons and an explicit fallbackPrompt templates
Answer blends two versionsConflicting sourcesDates in headers, conflict rulesConflicts
Wrong totals or comparisonsArithmetic over textText-to-SQL or code for calculationsText-to-SQL
Correct-looking but uncited claimsModel used its own knowledgeCitations, groundedness checksCitations

Debugging habits

  • Print the final prompt. Most mysteries disappear when you read exactly what the model saw.
  • Debug one failure fully before changing anything, then look for the same pattern in other failures.
  • Turn each fixed failure into a test case so it stays fixed.
  • Change one thing at a time and re-run the evaluation set.

Key takeaways

  • Trace wrong answers backwards: documents, chunks, retrieval rank, prompt, generation.
  • Each stage has its own class of fixes; fixing the wrong stage wastes effort.
  • Automate the trace with a helper and an evidence phrase.
  • Read the final prompt, fix one thing at a time, and add regression tests.