Contents

Foundation Model Engineering

Manuscript updated (UTC) · Chapter source on GitHub · Cite this chapter (RIS)

On this page

14.6 RAG Failure Modes and Operational Design

“The assistant cited our refund policy and still gave the wrong answer.” Replacing the embedding model is tempting, but the citation alone does not tell you what failed. The retriever may have found an obsolete policy, the context builder may have dropped an exception, or the generator may have ignored a passage it received.

RAG combines a generator with retrieved information [1]. To debug that combination, follow one answer all the way back to the source version. The worked incident below is fictional; its documents, counts, and deadlines are teaching examples, not a production benchmark.

1. Follow One Incorrect Answer

A customer asks: “I renewed my annual plan yesterday. Can I get a refund?” For this example, the authoritative policy says that first purchases have a 30-day window, while renewals have a seven-day window.

StageRecorded evidenceWhat it tells us
SourcePolicy v3 contains both windows and explicitly supersedes v2An authoritative answer exists
Candidate retrievalTop 20 includes v3’s renewal clause and v2’s old 30-day ruleCandidate retrieval found the needed evidence
RankingThe renewal clause is ranked eighthIt may still be lost before generation
Context constructionOnly the top five passages are sent; v2 survives, v3’s renewal clause does notThe generator never received the decisive passage
Answer“You have 30 days,” with a valid link to v2The citation exists, but the answer uses a superseded rule

There are two defects here: a lifecycle filter allowed a superseded source, and the evidence needed for this question did not survive context selection. Improving recall alone cannot repair either observation. Keep document version, chunk identifier, candidate rank, final context position, and truncation reason in the trace. Log identifiers and controlled excerpts rather than copying sensitive documents into general application logs.

This also explains why adding more context is not automatically the fix. Lost in the Middle found position-dependent performance on its evaluated long-context tasks [2]. Test evidence placement and distractors for your model; do not turn that paper into a rule that every model ignores every middle passage.

2. Use Interventions to Locate the Failure

Start with a small, human-labeled set of answerable and unanswerable questions. For each answerable question, label the authoritative evidence needed for the answer, including exceptions. Then rerun the same generator under controlled inputs:

ExperimentKeep fixedReplaceInterpretation if the answer improves
Reference-evidence runQuestion, generator, prompt, decodingSupply the labeled authoritative passageEvidence delivery is a bottleneck; inspect retrieval and context construction
Candidate-retention runRetrieved top 20, generatorEnsure required passages survive the context budgetRanking, packing, or truncation is implicated
Source-version runQuestion and retrieval settingsRemove superseded versions before retrievalSource lifecycle policy is implicated
Evidence-only checkAuthoritative passage and questionHuman or executable answer checkEstablish whether the task is answerable from that evidence at all

These are diagnostic interventions, not independent scores to add together. Several defects can coexist. A reference-evidence run that still fails suggests examining the prompt, generation, ambiguous question, or labeling before rebuilding the index.

Measure the stage boundaries explicitly. In an authored 100-question example, suppose required evidence is found for 90 questions, survives the context budget for 72, and leads to a supported correct answer for 60. The question-level evidence hit rate is 90%; evidence retention among hits is 72/90 = 80%; supported-answer success among retained cases is 60/72 ≈ 83.3%. End-to-end success is 60%, not 90%. Those nested counts assume these are the only successful cases; they are not a universal factorization of RAG accuracy. Multi-document tasks also need coverage of the full required evidence set, not just one relevant chunk.

Run a Trace Audit with Stable Chunk IDs

The same wrong number can arise at different boundaries. Run the following example and compare ranking-selection with context-packing: both have the correct candidate, but only the second still has it after the reranker’s cutoff. Keeping only the final answer and its citation would hide that difference.

Runnable diagnostic, not a RAG implementation: This Python 3 example checks six authored stage traces for the fictional renewal question. It uses hand-labeled source facts and the required evidence ID; retrieval, reranking, packing, and generation outputs are supplied fixtures. There are no dependencies, API calls, learned scores, or semantic entailment checks. Each retained ID represents an entire unchanged chunk.

# Python 3, standard library only. Authored traces; no model or network call.
RENEWAL = "refund:v3:renewal"
FIRST = "refund:v3:first-purchase"
OLD = "refund:v2:renewal"
# Human-labeled facts for this fictional question, not extracted semantics.
chunks = {
    RENEWAL: {"days": 7, "scope": "renewal", "current": True},
    FIRST: {"days": 30, "scope": "first-purchase", "current": True},
    OLD: {"days": 30, "scope": "renewal", "current": False},
}
required = {RENEWAL}

def audit(candidates, selected, packed, answer_days, citation):
    # selected is the reranker's cutoff; packed is the final intact context.
    assert set(candidates) <= chunks.keys()
    assert set(selected) <= set(candidates)
    assert set(packed) <= set(selected)
    for stage, ids in [("retrieval", candidates),
                       ("ranking-selection", selected),
                       ("context-packing", packed)]:
        if not required <= set(ids):
            return stage
    if answer_days != chunks[RENEWAL]["days"]:
        return "answer-value"
    cited = chunks.get(citation)
    supported = (citation in packed and cited is not None
                 and cited["current"] and cited["scope"] == "renewal"
                 and cited["days"] == answer_days)
    return "pass" if supported else "citation-attribution"

# Each trace stores candidate IDs, selected IDs, packed IDs, answer, citation.
cases = {
    "retrieval": ([FIRST, OLD], [FIRST], [FIRST], 30, FIRST),
    "ranking-selection": ([RENEWAL, FIRST], [FIRST], [FIRST], 30, FIRST),
    "context-packing": ([RENEWAL, FIRST], [RENEWAL, FIRST], [FIRST], 30, FIRST),
    "answer-value": ([RENEWAL], [RENEWAL], [RENEWAL], 30, RENEWAL),
    "citation-attribution": ([RENEWAL, FIRST], [RENEWAL, FIRST],
                             [RENEWAL, FIRST], 7, FIRST),
    "pass": ([RENEWAL], [RENEWAL], [RENEWAL], 7, RENEWAL),
}
for expected, trace in cases.items():
    result = audit(*trace)
    assert result == expected, (expected, result)
    print(f"{result}: packed={trace[2]}, cited={trace[4]}")

The program prints retrieval, ranking-selection, context-packing, answer-value, citation-attribution, and pass, with the exact context and citation IDs. In the answer-value case, the correct seven-day clause reached the generator but the recorded answer says 30. In citation-attribution, the answer is seven days but its citation points to the first-purchase clause: the answer value is correct and the attribution is false. Replacing that citation with RENEWAL repairs this fixture; merely linking to an existing chunk does not.

What this does not establish: The first missing boundary is an observation, not proof that its component caused the defect. An ingestion omission, access filter, wrong evidence label, or earlier source-version decision can produce a retrieval miss. With evidence present, a wrong answer warrants checks of the prompt, serialization, generation, and grading; it does not isolate model weights. Multiple defects can coexist, while this auditor returns only the first failed check.

In real traces, bind each ID to an immutable document revision and content hash. Log which text spans actually survived packing: retaining an ID while cutting away its exception would fool this toy check. Hand-labeled numeric fields cannot establish entailment for arbitrary claims, and a required-ID set can reject valid alternative evidence if the labels are incomplete. Use this audit to select the controlled intervention above, then inspect the cited text and test the repair.

3. A Similarity Score Is Not an Answer Probability

A cosine similarity of 0.82 does not mean an answer has an 82% chance of being correct. Score distributions change with the embedding model, corpus, query type, and candidate filtering. Rankers may also emit uncalibrated logits. Choose any threshold using labeled examples and the cost of a wrong answer, then measure the resulting coverage and error rate on a separate holdout.

For the refund question, checking the transaction type and policy version matters more than a universal similarity threshold. Ask for clarification if “purchase” could mean first purchase or renewal. Query the authorized transaction system when the answer depends on the customer’s actual renewal date. If no current policy can be verified, say that the policy cannot be confirmed instead of substituting the model’s general knowledge.

Self-RAG learns retrieval and critique decisions using reflection tokens [3]; CRAG evaluates retrieved evidence and selects corrective actions [4]. These are research designs for controlling evidence use. They do not supply calibrated thresholds, access permissions, or an unlimited retry budget for your application.

4. Treat Timeout Fallbacks as Separate Behaviors

Suppose an illustrative service reserves 1,000 ms before generation: 200 ms for retrieval, 250 ms for reranking, 150 ms for version/access checks and context construction, and 400 ms of slack. These are assigned budgets, not measurements. Enforce one request deadline; a second retrieval cannot restart the clock.

If the reranker times out, using first-stage order is acceptable only if that degraded path has passed its own evidence and answer-quality checks. A smaller candidate set can discard the one passage that matters. Preserve authorization and source-version filters on every path. If current evidence or required checks are unavailable, return an explicit limitation or route to a human. “The answer may be stale” is not a sufficient fallback for a definitive policy decision.

Track fallback frequency, evidence retention, unsupported-answer rate, abstention, and tail latency separately for normal and degraded paths. A fast fallback that confidently invents an answer is not a successful request.

5. Check Claims, Not Just Citation Markers

For each material claim, ask two questions: does the cited passage support it, and is that passage authoritative for this question? In the example, v2 supports a 30-day statement but fails the second question. A link checker would pass it; an evidence check should not.

Maintain separate measures for citation coverage (which claims have citations), citation support (whether the cited text entails the claim), and source validity (version, scope, and access). Treat retrieved text as data: an instruction inside a document must not change the assistant’s permissions or evaluation rules. Use deterministic checks for dates and identifiers where possible, with human-reviewed samples for semantic support.

6. Make the Repair Reviewable

A repair should include the failing question, allowed source versions, expected evidence, the old and new context traces, and the resulting answer. Keep related questions and source revisions together when splitting evaluation data so paraphrases of the incident do not become a misleading “unseen” release set.

Compare the change on a sealed set containing renewals, first purchases, missing dates, conflicting versions, unauthorized documents, and deliberately unavailable evidence. Record accuracy, supported answers, abstention coverage, critical errors, latency, and cost by slice. Apply predeclared release thresholds with uncertainty as described in production evaluation and release gates. Retain the previous index snapshot, ingestion/filter configuration, retriever/reranker versions, and prompt/model bundle so rollback restores one coherent pipeline.

The practical debugging question is: at which boundary did the required evidence disappear or become invalid? Answering it usually produces a more specific change than “use a better model.”

Quizzes

Quiz 1: The correct clause appears in the top 20 but not in the final top five. Which change should you test before replacing the embedding model? Inspect ranking, packing, and truncation, then run a candidate-retention intervention with the same retrieved set. The trace already shows that first-stage retrieval found the clause; also fix any source-version filtering defect.

Quiz 2: Why is a cosine score of 0.82 insufficient to authorize a policy answer? It is a similarity score, not a calibrated probability of answer correctness. The passage can be stale, scoped to a different transaction, or incomplete. Validate source authority and measure the threshold against labeled cases and decision costs.

Quiz 3: In the 100-question example, why is 90% evidence retrieval not 90% answer success? Only 72 cases retain the needed evidence, and only 60 produce a supported correct answer. The stage-conditioned rates are 80% retention and about 83.3% generation success; end-to-end success is 60% under the example’s stated assumptions.

Quiz 4: Is continuing without a reranker always safer than returning an error? No. The fallback changes the evidence supplied to the generator and can exclude a decisive exception. Validate it separately, preserve access and version checks, and abstain or escalate if its requirements fail.

Quiz 5: Can a citation be textually supported and still produce a wrong answer? Yes. An obsolete or out-of-scope policy may support the quoted statement while being invalid for the user’s case. Citation support and source validity are separate checks.

References

  1. Lewis, P., et al. (2020). Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks. arXiv:2005.11401.
  2. Liu, N. F., et al. (2023). Lost in the Middle: How Language Models Use Long Contexts. arXiv:2307.03172.
  3. Asai, A., et al. (2024). Self-RAG: Learning to Retrieve, Generate, and Critique through Self-Reflection. arXiv:2310.11511.
  4. Yan, S.-Q., et al. (2024). Corrective Retrieval Augmented Generation. arXiv:2401.15884.