RAG Failed — But Which Layer Actually Failed? A Diagnostic Method

When a RAG answer is wrong, blaming retrieval or the model is too vague. This diagnostic method isolates source coverage, query construction, retrieval, ranking, context assembly, generation, evidence attribution, and freshness—so the actual failure can be reproduced and fixed.
Published:
Aleksandar Stajić
Updated: September 25, 2026 at 10:46 PM
RAG Failed — But Which Layer Actually Failed? A Diagnostic Method

A RAG system returns a weak, wrong, incomplete, or unsupported answer. The usual diagnosis is “retrieval failed” or “the model hallucinated.” Both labels are too broad to be useful. A production RAG pipeline can fail before retrieval, during retrieval, while ranking, while assembling context, during generation, or after generation when evidence and validity are checked.

Why “RAG failed” is not a diagnosis

Retrieval-augmented generation combines several mechanisms: a user request is interpreted, one or more searches are constructed, candidate material is retrieved, results are filtered or reranked, selected evidence is inserted into a model context, and a model generates an answer. Production systems may add permissions, metadata filters, freshness rules, citations, query rewriting, hybrid search, tool calls, memory, and external state.

A wrong final answer therefore does not tell you which component failed. The model may have received the wrong evidence. It may have received the right evidence mixed with too much noise. The evidence may be correct but stale. The source may never have contained the answer. Or the model may have ignored perfectly adequate context.

OpenAI's RAG guidance already makes a fundamental distinction between retrieval failure and model failure: a system can supply the wrong context, or it can supply the right context and still generate the wrong answer. AWS similarly separates retrieve-only evaluation from retrieve-and-generate evaluation. For production diagnosis, that distinction should be taken further.

The RAG Failure Stack

LayerQuestionTypical failure
1. Source coverageDoes the required evidence exist in an allowed authoritative source?The corpus cannot answer the question at all
2. Query constructionDid the system search for the right thing?Intent, entities, filters, language, or time constraints are lost
3. Candidate retrievalDid the relevant evidence enter the candidate set?Low recall; the right chunk is never retrieved
4. Ranking & filteringDid the right evidence survive and rank high enough?Relevant evidence is buried, filtered out, or outranked by superficially similar text
5. Context assemblyDid the model receive usable evidence?Truncation, bad chunk boundaries, duplicates, conflicting passages, or context overload
6. GenerationDid the model use the supplied evidence correctly?Unsupported inference, instruction failure, reasoning error, or refusal mismatch
7. Evidence attributionCan the answer be traced to the evidence it claims to use?Missing, weak, or incorrect citations; claims exceed retrieved support
8. Validity & freshnessIs the evidence still valid for this question now?Correct historical evidence is reused outside its valid time, version, jurisdiction, or state

Layer 1 — Source coverage: can the system answer this at all?

Before tuning embeddings, rerankers, or prompts, verify that the answer exists in the knowledge space the system is allowed to use. This sounds obvious, but many RAG failures are actually corpus failures. The requested fact may be absent, hidden in an unindexed attachment, available only in a newer document, stored in a system outside the RAG corpus, or blocked by permissions.

A retrieval metric cannot recover information that was never indexed. A larger top-k cannot retrieve a document the pipeline does not contain. If the source coverage test fails, the correct fix is ingestion, source selection, permissions, or an explicit “not answerable from available evidence” behaviour.

Layer 2 — Query construction: did the system ask the corpus the right question?

The user query is not always the retrieval query. Production systems rewrite questions, resolve pronouns, extract entities, translate languages, add metadata constraints, split complex questions, or generate multiple searches. Every transformation can improve retrieval, but every transformation can also destroy information.

A request such as “Does the policy still apply to contractors in Germany after the September update?” contains at least an entity, a population, a jurisdiction, and a time boundary. A rewritten query that becomes “contractor policy” may retrieve semantically related text while losing the variables that decide whether the answer is valid.

Layer 3 — Candidate retrieval: did the relevant evidence enter the set?

Candidate retrieval is primarily a recall problem. The diagnostic question is not yet whether the best result ranked first; it is whether relevant evidence appeared anywhere in the candidate pool. If the known correct source does not appear, investigate indexing, chunking, embeddings, lexical matching, metadata, hybrid search, language handling, synonyms, and query expansion.

This is where retrieval-only evaluation is valuable. AWS exposes context relevance and context coverage for retrieve-only RAG evaluation. The important production habit is to evaluate retrieval before generation so that a polished final answer cannot hide a weak candidate set.

Layer 4 — Ranking and filtering: was the right evidence discarded or buried?

A system can have good recall and still fail because the relevant evidence ranks below noisy but semantically similar material. Rerankers, recency boosts, authority weights, language preferences, tenant filters, access controls, product status filters, and deduplication all change what survives into the final context.

Debugging should therefore preserve the full candidate list, not only the final top-k. If the gold evidence was retrieved at rank 18 and a reranker removed it, the fix is not the same as a retrieval miss.

Layer 5 — Context assembly: did useful evidence become usable context?

Retrieval success does not guarantee context success. Relevant chunks can be truncated, separated from their qualifiers, duplicated until they dominate the prompt, mixed with contradictory versions, or surrounded by enough irrelevant text that the decisive passage loses salience.

Chunk boundaries are especially important. A sentence may contain the rule while the following sentence contains the exception. If they are indexed separately and only the first is retrieved, the retriever can appear relevant while the assembled context becomes misleading.

Layer 6 — Generation: can the model use correct evidence correctly?

Once the system has demonstrably supplied sufficient evidence, generation becomes independently testable. The model may overgeneralize, combine incompatible passages, ignore a negative statement, fail to follow the requested answer format, invent a bridge between facts, or answer from parametric memory instead of the retrieved evidence.

This is why end-to-end correctness alone is insufficient for diagnosis. OpenAI recommends evaluation as a structured way to understand application behaviour, while Anthropic's agent-evaluation guidance emphasizes multiple trials, graders, traces, and realistic failure cases. For RAG, the generator should be tested both with normal retrieval and with controlled gold context.

Layer 7 — Evidence attribution: is the answer actually supported?

A plausible answer with citations can still be weakly grounded. The cited document may be relevant to the topic but not support the specific claim. One sentence may be supported while another is inferred. A citation may point to a source that contradicts the answer once its conditions are read.

Citation evaluation therefore belongs after generation. AWS distinguishes citation precision from citation coverage: whether cited passages are correctly cited and whether the answer is sufficiently supported by citations. In production, claim-level support is more useful than treating the presence of any citation as evidence quality.

Layer 8 — Validity and freshness: was the evidence correct for this version of reality?

RAG can retrieve a perfectly authentic, highly relevant, faithfully quoted source and still produce a wrong answer if the source is no longer valid for the current question. Policies change. APIs are deprecated. prices move. software behaviour changes between versions. product inventory changes. permissions change. game patches change mechanics.

This is a separate failure class from hallucination. The evidence is real; its applicability is wrong. A robust system therefore needs timestamps, version or jurisdiction metadata where relevant, source authority, supersession rules, and an explicit mechanism for deciding when older evidence must be restricted or abandoned.

The fastest isolation method: the oracle-context test

The most useful first split is simple: manually provide the generator with a small set of evidence that you know is sufficient to answer the question. Keep the task and expected answer unchanged.

Oracle-context test

ResultLikely interpretationNext diagnostic step
Answer becomes correct
Answer remains wrong
Answer improves but remains incomplete

A production diagnostic sequence

Diagnose the failure from evidence to answer

1
1. Define the expected claim
Write the expected answer, allowed uncertainty, and the evidence that would justify it.
2
2. Verify source coverage
Confirm that authoritative and permitted evidence exists in the indexed or reachable source set.
3
3. Run the oracle-context test
Supply sufficient gold evidence directly to the generator and observe whether the answer becomes correct.
4
4. Inspect the retrieval query
Check rewrites, entities, filters, language, time constraints, decomposition, and hidden assumptions.
5
5. Inspect candidates before reranking
Determine whether relevant evidence was retrieved at all and record its rank.
6
6. Inspect ranking and context assembly
Check reranking, metadata filters, truncation, chunk boundaries, duplicates, conflicts, and top-k composition.
7
7. Grade generation and citations separately
Measure answer correctness, completeness, faithfulness, and claim-level evidence support.
8
8. Test validity boundaries
Check whether version, date, state, jurisdiction, permissions, or superseding evidence changes the answer.

Do not change three layers at once

A common debugging mistake is to change embeddings, chunk sizes, top-k, prompts, and the model in one iteration. If the score improves, you do not know why. If it gets worse, you do not know which change caused the regression.

Treat RAG debugging like experimental diagnosis: hold as much of the pipeline constant as possible and replace one uncertain component with a controlled input. Gold documents isolate retrieval. Gold chunks isolate chunk selection. Fixed context isolates generation. A fixed model isolates retrieval changes. A fixed corpus isolates ingestion and indexing changes.

A failure matrix for common RAG symptoms

SymptomMost likely layers to test firstDiscriminating test
No relevant source appearsSource coverage → Query → Candidate retrievalSearch the corpus manually, then inspect rewritten query and unfiltered candidates
Relevant source appears but answer is wrongContext assembly → GenerationOracle-context test with the same source reduced to decisive passages
Answer is correct sometimes, wrong other timesRanking → Context assembly → Generation variabilityRepeat trials while logging retrieved set, rank, prompt context, and model output
Answer cites the right document but overstates itGeneration → Evidence attribution → ValidityGrade each claim against the exact cited passage
Old information keeps winningRanking → Validity/freshnessCompare with recency/supersession rules and inspect metadata
Answer misses an exceptionChunking → Context assemblyCheck whether rule and exception were split or truncated
Adding more top-k makes quality worseRanking → Context overloadAblate low-value chunks and compare with a minimal evidence set
Changing the model fixes the answerGeneration, but not necessarily retrievalRepeat with identical retrieved context across models
Changing embeddings fixes the answerRetrieval/rankingKeep generator and context template constant while comparing candidate recall

Measure each layer with the metric it can actually influence

LayerUseful measurementsWhat not to infer
Source coverageAnswerable-question rate, corpus coverage, ingestion completenessDo not blame embeddings for missing source material
Candidate retrievalRecall@k, hit rate, context coverageHigh recall does not prove ranking quality
RankingMRR, NDCG, gold rank, precision@kGood ranking does not prove the generator used the evidence
Context assemblyEvidence retention, duplication, contradiction rate, token utilizationLarge context does not mean useful context
GenerationCorrectness, completeness, task success, faithfulnessCorrectness alone does not prove grounding
Evidence attributionCitation precision, citation coverage, claim supportA citation count is not evidence quality
ValidityFreshness, supersession accuracy, version/jurisdiction matchRelevant evidence is not automatically applicable evidence

A correct answer can still hide a RAG defect

The reverse problem also matters. A RAG system can produce the correct answer while retrieval is broken. The model may already know the answer from training, infer it from weak evidence, or guess correctly. If evaluation looks only at the final answer, the system can appear healthy until the question reaches information that exists only in the private corpus.

This is the same reliability problem that appears in agent systems more broadly: outcome correctness is not enough to prove that the execution path was reliable. For RAG, traces should preserve at least the retrieval query, candidate set, ranking, final context, answer, citations, model version, corpus/index version, and relevant filters.

Use competing hypotheses, not a favourite explanation

If a bad answer immediately becomes “an embedding problem,” the investigation is already biased. A stronger debugging method writes down competing hypotheses before changing the system: missing source, bad query rewrite, low retrieval recall, bad reranking, context truncation, conflicting versions, generation failure, citation failure, or stale evidence.

Then choose a test that would separate those hypotheses. This is more efficient than collecting more examples that support the first explanation. The same principle applies to AI-assisted technical reasoning in general: a useful diagnosis is one that survives discriminating tests, not one that merely sounds plausible.

What would change this answer?

The exact diagnostic layers change with architecture. A simple single-document RAG application may have no query rewriting, reranker, or citation layer. An agentic retrieval system may add planning, multiple searches, tool selection, memory, permissions, and iterative evidence gathering. A structured database lookup may not use chunks or embeddings at all.

The core method still holds: identify the components that can independently change the result, construct controlled tests that replace uncertain components with known-good inputs, and measure each component using evidence appropriate to that layer.

Limitations

Real failures are often coupled. A weak query can reduce recall, which changes reranking, which changes context, which increases generation variance. The oracle-context test is a diagnostic shortcut, not proof that one component is solely responsible. Evaluation datasets can also be unrepresentative, and model-based graders can introduce their own errors.

The proposed stack is therefore best used as an investigation structure: log the pipeline, isolate variables, reproduce failures, test competing explanations, and keep end-to-end evaluation after layer-level fixes.

Conclusion

“RAG failed” should be the beginning of the investigation, not the conclusion. A useful diagnosis identifies whether the system lacked the evidence, searched incorrectly, failed to retrieve it, ranked it badly, assembled unusable context, generated incorrectly, attributed claims poorly, or applied evidence outside its validity boundary.

The practical rule is simple: replace uncertainty with controlled evidence one layer at a time. Start with the oracle-context test. Separate retrieval-only evaluation from generation evaluation. Preserve the full trace. Then fix the component that actually failed instead of tuning the entire RAG stack by intuition.

FAQ

RAG failure diagnosis

How can I tell whether RAG retrieval or the LLM failed?

Give the model a small set of known-correct evidence manually. If the answer becomes correct, investigate source coverage, query construction, retrieval, ranking, and context assembly. If the model still fails with sufficient evidence, retrieval is not the primary problem.

Can RAG fail even when the correct document was retrieved?

Yes. The relevant passage can be ranked too low, truncated, separated from an exception, mixed with conflicting evidence, overwhelmed by irrelevant context, or used incorrectly by the generator.

Is answer correctness enough to evaluate a RAG system?

No. A model can produce a correct answer despite weak retrieval by relying on prior model knowledge or chance. Evaluate retrieval and evidence support separately from final-answer correctness.

What should I log when debugging RAG?

At minimum log the user request, transformed retrieval query, filters, candidate documents and ranks, final selected context, model and prompt version, answer, citations, corpus/index version, and timing or version metadata relevant to freshness.

Does increasing top-k usually fix RAG?

Not reliably. A larger candidate or context set may improve recall, but it can also add noise, contradictions, duplicates, and context overload. Test whether the relevant evidence is missing before increasing top-k.

Glossary

Key diagnostic terms

Oracle-context test
A controlled test in which the generator is given known-sufficient evidence directly to determine whether the dominant failure is upstream of generation.
Candidate retrieval
The stage that selects an initial set of potentially relevant documents, chunks, records, or passages before final ranking or context assembly.
Context assembly
The process of converting retrieved evidence into the actual model input, including ordering, truncation, deduplication, formatting, and token-budget decisions.
Faithfulness
The degree to which generated claims remain supported by the retrieved or supplied evidence rather than introducing unsupported content.
Context coverage
A retrieval-oriented measure of whether selected evidence covers the information needed to answer the question.
Validity boundary
The conditions under which a claim or answer remains applicable, such as time, version, jurisdiction, state, population, permissions, or source assumptions.

Primary sources and further reading

OpenAI — Optimizing LLM Accuracy

OpenAI guidance separating retrieval failures from LLM failures in RAG applications.

OpenAI — Evaluation Best Practices

Guidance on structured evaluation for variable AI systems and production-oriented test design.

Amazon Bedrock — RAG Evaluation Metrics

Documentation separating retrieve-only metrics from retrieve-and-generate metrics, including context relevance, coverage, faithfulness and citation measures.

Anthropic — Demystifying Evals for AI Agents

Practical evaluation guidance on tasks, trials, graders, traces, regressions and production behaviour.

Google Cloud — Retrieval-Augmented Generation

Overview of RAG architecture and the importance of relevant retrieval and grounded generation.

Related Articles

AI Agent Memory Is Not RAG: How to Separate Memory, Retrieval, State and Context

AI Agent Memory Is Not RAG: How to Separate Memory, Retrieval, State and Context

Agent memory, RAG, state, and context are often used as if they were interchangeable. They are not. This practical architecture model separates the four layers, shows where each belongs, and explains what breaks when systems collapse them into one.

Comprehensive Guide to Evaluation Harness: Mastering LLM Performance Evaluation

Comprehensive Guide to Evaluation Harness: Mastering LLM Performance Evaluation

This guide provides a detailed walkthrough of Evaluation Harness, an essential framework for rigorously assessing large language model (LLM) capabilities in enterprise LLMOps pipelines. Learn setup, best practices, and advanced techniques to ensure reliable model benchmarking and optimization.

Ollama Is Not the Product: Building Production-Ready Open-LLM Applications

Ollama Is Not the Product: Building Production-Ready Open-LLM Applications

Running a local model with Ollama is easy. Building a production-ready Open-LLM application is harder: it requires RAG, access control, provider abstraction, evaluation, logging, deployment discipline and a controlled application layer around the model.

Computer-Use Agents: Why a Successful Demo Can Still Be an Unreliable System

Computer-Use Agents: Why a Successful Demo Can Still Be an Unreliable System

Computer-use agents can now complete impressive browser and desktop workflows, but one successful run proves capability—not reliability. This article shows how to test repeatability, environmental robustness, long-horizon control, state awareness, outcome verification, and safe goal handling.

Managed Agent Harness vs Self-Hosted Agent Loop: What You Gain, What You Lose

Managed Agent Harness vs Self-Hosted Agent Loop: What You Gain, What You Lose

“Self-hosted agent” can mean very different architectures. This guide separates the managed harness, self-hosted execution environment, and fully self-operated agent loop—and shows which control boundary teams actually need.

AI Agent Reliability: Why the Final Answer Is Not Enough

AI Agent Reliability: Why the Final Answer Is Not Enough

Correct output does not prove correct reasoning, safe execution, or a trustworthy system.

Mastering the SEO Workflow: Essential Optimization Strategies for Organic Growth

Mastering the SEO Workflow: Essential Optimization Strategies for Organic Growth

A structured SEO workflow is crucial for sustainable organic growth. Learn the ten foundational strategies, from keyword research and technical optimization to content quality and performance analysis.

What Is RAG? The Simplest Explanation of How It Works

What Is RAG? The Simplest Explanation of How It Works

RAG sounds complicated, but the idea is simple: before an AI answers, it first looks up useful information from a knowledge source and gives that information to the language model. This guide explains RAG, LLMs, state, memory and tools using one simple mental model.