Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 5 of 6 · Concept · 15 min · revision 2

Common RAG Failure Modes

Recognise the ways a RAG system gives a wrong answer (missing content, chunking losses, retrieval and ranking misses, evidence dropped during assembly, and generation errors), trace a wrong answer to the first stage that lost the evidence, and pick the fix that targets that stage.

Contentsand lesson path

What you will learn

  • Explain when RAG is preferable to prompting alone, long context or fine-tuning, given a knowledge source's size, freshness and access rules.
  • Improve retrieval with query rewriting or reranking and show the effect on a fixed query set.

Prerequisites: Vector Search Foundations, Chunking, LLM API Integration

01. Why it matters

A wrong answer looks the same whichever stage caused it: fluent, confident and wrong. The temptation is to fix what is easiest to change, often the prompt or the model. If the evidence never reached the prompt, no prompt and no model can ground the answer in it, and a week of prompt tuning ends where it started.

Barnett et al. (2024) collected the failures of three RAG systems built for research, education and biomedical use and named seven failure points. One of their two key takeaways shapes this lesson: validation of a RAG system is only feasible during operation, so a system needs a way to diagnose failures once real users ask real questions. The method is the framing of this lesson, not of the paper: each failure point can be placed at a pipeline stage, so the diagnosis is a search for the first stage that lost the evidence. The lesson orders the failure modes by stage, then turns the search into a script.

02. Failure modes, stage by stage

Before retrieval, in the knowledge itself:

  • Missing content. The documents do not answer the question. The right behaviour is the abstention from lesson 2; the failure is a plausible answer from the model's own knowledge. It is the first failure point in Barnett et al.'s list, and it occurs whenever users ask about something the docs never covered.
  • Parsing and chunking losses. The answer is in a document but no chunk holds it intact: a table flattened by the parser, a sentence cut between two chunks, a scanned page with no text. The Chunking skill covered the causes; here it is enough to recognise the symptom, which is evidence that belongs to no single chunk.
  • Stale or conflicting content. Two versions of a page disagree, or the index lags behind an edit. The model faithfully reports the wrong one.

In retrieval and assembly:

  • Retrieval miss. The evidence chunk exists but is not among the candidates, usually because the question uses other words than the docs, or because a filter excluded it.
  • Ranking loss, which Barnett et al. call missed the top ranked documents. The evidence is among the candidates but below the cut-off k, as q07 was in the lab.
  • Lost during assembly, their not in context. The evidence ranked high enough but was dropped on its way into the prompt: by deduplication, by a token budget that a long chunk did not fit, or by truncation.
  • Access leak. The reverse failure: a chunk the user may not see reached the prompt because an access filter was missing or came from the wrong place, as discussed in lesson 3. It is a security bug, not a quality bug.

In generation, with the evidence in the prompt:

  • Not extracted. The model misses or misreads the evidence, often because other sources are noisy or contradict it, or because the evidence sits in the middle of a long context.
  • Unsupported claims. The answer adds details that no source contains, sometimes with a citation that does not support them. The Grounding and Citations skill checks each claim against its source.
  • Incomplete and incorrect specificity. The answer is true but leaves out part of what the sources say, or is too general or too detailed for what was asked.
  • Wrong format. The answer ignores the requested shape, such as a list, a JSON object or a citation style. A schema with validation and the provider's structured-output mode, from the Prompt Basics skill, fix this more reliably than stronger wording.

03. Follow the evidence

For a question with labelled evidence the search for the failing stage can be automated: check, in pipeline order, where the evidence chunk was last seen. trace.py does this for the Larkspur pipeline, using contains() and LABELS from measure.py in the lesson 4 lab and the lesson 2 functions, so run it in the same chunk-lab folder:

Python · trace.py
"""Follow one question's evidence through the pipeline; name the stage that lost it."""
import re
import sys

from measure import LABELS, contains
from models import fake_model
from prompt import NOT_FOUND, SYSTEM, build_prompt
from retrieve import load_index, search


def trace(question: str, span: tuple, k: int = 3, candidates: int = 10) -> str:
    _, _, records = load_index()
    holders = {r["chunk_id"] for r in records if contains(r, span)}
    if not holders:
        return "no chunk holds the whole evidence: parsing or chunking"
    hits = search(question, candidates)
    rank = next((n for n, h in enumerate(hits, 1) if h.chunk_id in holders), None)
    if rank is None:
        return f"evidence not in the top {candidates} candidates: retrieval"
    if rank > k:
        return f"evidence at rank {rank}, only {k} sent: ranking"
    user, ids = build_prompt(question, hits[:k])
    sent_as = next(sid for sid, chunk_id in ids.items() if chunk_id in holders)
    reply = fake_model(SYSTEM, user)  # swap in claude_model to trace the real thing
    cited = re.findall(r"\[(S\d+)\]", reply)
    if reply == NOT_FOUND:
        return f"evidence sent as {sent_as}, reply says not found: generation"
    if sent_as not in cited:
        return f"evidence sent as {sent_as}, reply cites {cited}: generation"
    return f"evidence sent as {sent_as} and cited: now read the answer itself"


if __name__ == "__main__":
    for qid in sys.argv[1:]:
        q = next(q for q in LABELS if q["qid"] == qid)
        print(f"{qid}  {trace(q['question'], q['spans'][0])}")
Terminal
python trace.py q05 q07 q08 q09
Expected output
q05  evidence sent as S1 and cited: now read the answer itself
q07  evidence at rank 6, only 3 sent: ranking
q08  evidence sent as S1, reply says not found: generation
q09  evidence sent as S1, reply cites ['S2']: generation
  • q05 passed every check. The script cannot judge the wording, so a person, or later an evaluation, reads the answer.
  • q07 is the ranking loss from the lab: the reranker or a multi-query search fixes it, and a better prompt would not.
  • q08 (How long does Larkspur wait between retries?) is a generation failure: the evidence was S1, but it says the delay doubles after each attempt and shares almost no words with the question, so the word-matching fake gave up. That is the not extracted pattern. A real model usually connects wait with delay; trace with claude_model to see.
  • q09 is the failure you saw in lesson 2: the evidence was S1 and the reply cited S2.

Two failures were generation and one was ranking. A new embedding model cannot fix the two generation failures, and for q07 the reranker from the lab is the smaller fix that you have already measured. Questions without labelled evidence need a manual trace with the same order of checks: search the documents for the answer, then the chunks, then the candidates, then the prompt, then the reply. When the answer is in no document, the failure is missing content. In a running system, log each request's query, candidate IDs and scores, sources sent and reply, so that a reported wrong answer can be traced later.

04. Fix the stage that failed

Once the stage is known, the fix is usually one of a few:

  • Missing content: add or correct the document; make sure the abstention works and count abstentions, since they are a list of questions your docs do not answer.
  • Parsing and chunking: fix the parser for that format, or change chunk size and boundaries, and check recall again on the labelled set.
  • Retrieval miss: add keyword search (hybrid search from the Vector Search skill), rewrite or expand the query, or check the filter; try a stronger embedding model last, since it means re-embedding everything.
  • Ranking or assembly loss: rerank, raise the token budget for sources, or merge neighbouring chunks so the evidence travels with its context.
  • Generation: tighten the answer prompt, ask the model to quote the relevant passages before answering (a technique Anthropic's prompting guide recommends for long documents), send fewer and better sources, or use a stronger model.

After the change, rerun the whole fixed question set, not only the question that failed. A fix for one stage can break another question elsewhere, which is why the lab reported the questions that moved in either direction.

05. Check your understanding

Practice check · 3 questions

Naming the failure

Apply the failure modes and the order of checks from this lesson. Each question has one best answer.

Q1. trace.py reports: "evidence at rank 5, only 3 sent: ranking". Which change targets this stage?
Q2. No Larkspur page mentions Kubernetes, yet the assistant replies that Larkspur ships a Helm chart. What went wrong?
Q3. A question asks how often a failed job is retried and what happens after the last retry. Both facts are in S1, but the answer gives only the retry count. Which failure is this?
Practice only: not graded, not saved, not evidence.

06. Apply it

Use your practice tool and its test set:

  1. Copy trace.py, point it at your labels, and replace fake_model with claude_model.
  2. Trace every question that was still answered wrongly after you added the reranker in lesson 4.
  3. Add a section to DECISION.md with one line per failure: question, failing stage, and the fix you would try first.
  4. Ask three questions your docs do not answer and confirm that the tool abstains with the exact sentence. If it does not, fix the prompt and rerun all 15 questions.

07. Review prompt

Without looking back, answer in your own words:

  1. Name the failure modes of a RAG system in pipeline order, from the documents to the answer.
  2. In what order do you check a wrong answer, and why does the first stage that lost the evidence matter more than the last?
  3. What is the difference between a retrieval miss and a ranking loss, and which fixes target each?
  4. Which request data should a production system log so that a wrong answer can be traced later?

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

6 questions · about 5 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check