Sub topic 2
Retrieval Failures Versus Generation Failures
This chapter assumes you know how a RAG pipeline works: chunking, embedding, vector search, and prompting an LLM with the retrieved text. It also assumes you can read Python and know precision and recall from classification. Here you learn to separate the two places a RAG system can go wrong. Every later chapter builds on this split.
Two components, two kinds of error
A RAG system has a retriever and a generator. The retriever takes a question and returns a ranked list of passages. The generator takes the question and those passages and writes an answer.
Each component can fail on its own. Because the generator only sees what the retriever hands it, a retrieval error often looks like a generation error in the final answer. A wrong answer tells you the system failed. It does not tell you which part failed.
- A retrieval failure happens when the passages given to the generator do not contain what is needed to answer the question, or contain it too far down the list to be used.
- A generation failure happens when the passages contain what is needed, but the answer does not correctly use them.
Retrieval failures
Retrieval failures fall into a few common patterns.
- Missing evidence. The passage that answers the question is not in the top k results. The cause may be a weak embedding match, a chunk boundary that split the answer in two, or a question phrased very differently from the source text.
- Buried evidence. The right passage is retrieved but ranked low. If you pass only the top 3 passages to the generator, a relevant passage at rank 7 might as well be absent.
- Noisy context. The right passage is present, but surrounded by irrelevant or near-duplicate passages. Extra text distracts the generator and uses up the context window.
- Conflicting context. Two retrieved passages disagree, for example an old and a new version of a policy. The retriever did its job in a literal sense, but the generator now has to choose.
- Nothing to retrieve. The corpus does not contain the answer. The correct behavior is to say so. This is a boundary case, covered below.
Retrieval metrics (precision@k, recall@k, MRR, nDCG) measure these problems directly, without calling the generator at all. That makes them cheap and repeatable. The next chapters introduce each one.
Generation failures
Generation failures happen even when the context is good.
- Unfaithful answer (hallucination). The answer states something the passages do not support. The generator may fill a gap from its training data or invent a detail that sounds plausible.
- Contradiction. The answer says the opposite of what a passage says.
- Ignored context. The passages contain the answer, but the generator answers from memory or says "I don't know."
- Off-target answer. The answer is accurate and grounded, but addresses a different question than the one asked.
- Bad synthesis. The answer needs facts from two passages, and the generator combines them incorrectly.
Faithfulness and answer relevance, covered later, measure these. Faithfulness asks whether the answer is supported by the retrieved context. Answer relevance asks whether the answer addresses the question.
Faithful does not mean correct
Keep one distinction in mind from the start. An answer is faithful if the retrieved context supports it. An answer is correct if it matches the real world, or a reference answer.
These can disagree in both directions.
| Retrieved context | Answer | Faithful? | Correct? |
|---|---|---|---|
| Says the warranty lasts 24 months | "The warranty lasts 24 months" | Yes | Yes |
| Outdated page says 12 months; real policy is 24 | "The warranty lasts 12 months" | Yes | No |
| Does not mention duration | "The warranty lasts 24 months" (from memory) | No | Yes (by luck) |
| Does not mention duration | "The warranty lasts 5 years" | No | No |
The second row is a retrieval failure that produces a faithful but wrong answer. The generator did exactly what it should. The third row is a generation failure that happens to produce a right answer. If you measure only correctness, the third row looks fine, and you would miss a system that is guessing.
Using the context to classify a failure
For a single question with a known bad answer, you can sort the failure with two checks.
- Was the needed evidence in the retrieved context? Use your relevance labels, or read the passages.
- Does the answer follow from the context it was given? Check whether each statement is supported.
Combining the two checks gives four cases.
| Evidence in context? | Answer supported by context? | Likely diagnosis |
|---|---|---|
| No | Yes (or the answer is "not found") | Retrieval failure. The generator worked with what it had. |
| No | No | Both failed: retrieval missed the evidence and the generator invented content. |
| Yes | No | Generation failure. The evidence was available and not used correctly. |
| Yes | Yes | Neither failed on this question. If the answer is still wrong, suspect the labels, the question, or conflicting passages. |
A small helper makes this classification explicit. It assumes you already have the two booleans from your labels and a faithfulness check.
def classify_failure(evidence_in_context: bool, answer_supported: bool) -> str:
if not evidence_in_context and answer_supported:
return "retrieval failure"
if not evidence_in_context and not answer_supported:
return "retrieval and generation failure"
if evidence_in_context and not answer_supported:
return "generation failure"
return "no failure detected; check labels and conflicting passages"
cases = [
(False, True),
(False, False),
(True, False),
(True, True),
]
for evidence, supported in cases:
print(evidence, supported, "->", classify_failure(evidence, supported))Later chapters show how to compute both inputs at scale. For now, the point is that the two checks are independent and you need both.
Edge cases that blur the line
The clean split has exceptions. Knowing them prevents wrong diagnoses.
Questions with no answer in the corpus
If the corpus lacks the answer, no retriever can succeed. The right behavior is for the generator to decline. Here an answer like "The documents do not say" is a success. Count it separately. If you mark these questions as retrieval failures, your recall numbers will look worse than the retriever deserves. Include some of these unanswerable questions in your evaluation set, because they test whether the generator invents answers when evidence is missing.
Partial evidence
Sometimes the context holds part of the answer. A question like "What are the warranty length and the claim process?" may retrieve only the length. A faithful answer covers only that part, and may look incomplete. Decide in advance whether you score completeness, and where.
Evidence in context, but too long
A relevant passage may be present but sit in the middle of a very long prompt. Some models use information in the middle of a long context less reliably than information at the start or end. This is a generation failure on paper, but a retrieval or prompt-assembly change (fewer passages, better ordering) can fix it. Treat the diagnosis as a pointer to where to look, not as proof of which team owns the fix.
Conflicting passages
When passages disagree, a faithful answer can still be wrong. Faithfulness only checks support from the context, so it will not flag this. The fix is usually upstream: remove stale documents, add metadata filters, or rerank by date.
Failures that interact
Retrieval quality can change generator behavior. A generator that handles clean context well may fail on noisy context. When you change one component, re-measure both. A better retriever that returns more partial matches can raise hallucination if the generator was relying on obvious answers.
What to measure for each side
This table maps the failure types to the measurements covered in the rest of the tutorial.
| Failure | What goes wrong | Main measurement |
|---|---|---|
| Missing evidence | Relevant passage not retrieved | recall@k, hit rate |
| Buried evidence | Relevant passage ranked low | MRR, nDCG |
| Noisy context | Many irrelevant passages | precision@k, context relevance |
| Unfaithful answer | Claims unsupported by context | faithfulness |
| Off-target answer | Answer ignores the question | answer relevance |
| Wrong citation | Cited passage does not support the claim | citation accuracy |
Common mistakes
- Judging by the final answer only. You end up tuning the prompt when the real problem is retrieval, or the reverse.
- Treating "I don't know" as always bad. It is correct when the evidence is not there.
- Assuming a faithful answer is right. Faithfulness is relative to the context, and the context can be wrong or stale.
- Running no checks on the labels. If your "relevant" labels are incomplete, a good retriever looks like it fails. Chapter three covers how to build labels carefully.
Exercise
A user asks, "How long is the return window?" The retriever returns three passages. None mention a return window. The generator answers, "You have 30 days to return items." The true policy is 30 days. Is the answer faithful, is it correct, and which component should you investigate first?
Show answer
The answer is correct, since the true policy is 30 days. It is not faithful, because no retrieved passage supports it. The evidence was missing from the context, so retrieval failed. The generator also failed, because it answered from memory instead of saying the documents do not cover the question. Investigate retrieval first, since the evidence is missing and that is the root cause. Then check the generator's behavior when the context lacks the answer, because the correct 30 days was luck and the same behavior could produce a wrong number on another question.
Exercise
Your retriever has recall@5 of 0.95, but faithfulness on the final answers is 0.60. Which side do these numbers point to, and why?
Show answer
They point to the generator. Recall@5 of 0.95 means the relevant evidence usually appears in the top 5 passages, so the retriever is mostly doing its job. Low faithfulness means many answer claims are not supported by that context. Next, inspect the failing cases for ignored context, hallucinated details, or very long and noisy prompts. High recall alone does not rule out noise, so also check precision@k and context relevance.