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.
Two parts, two kinds of failure
A RAG system has two parts that can fail independently. The retriever finds passages for a question. The generator is the LLM that writes an answer from those passages. A bad final answer can come from either part, and the fix depends on which one.
Retrieval failures
A retrieval failure happens when the context does not contain what the generator needs. Common forms:
- Miss: the relevant passage is in the index but not in the top k results.
- Noise: the top k results are mostly irrelevant, so the useful passage is buried.
- Fragmentation: the answer is split across chunks, and only some of them are retrieved.
- Absent knowledge: the index never contained the answer at all.
Even a perfect generator cannot answer correctly from context that lacks the facts. You measure these failures with retrieval metrics such as precision@k and recall@k, which later chapters cover.
Generation failures
A generation failure happens when the context is adequate but the answer is still bad. Common forms:
- Unfaithful answer: the answer states things the context does not support. This is often called hallucination.
- Ignored context: the model answers from its own memory and disregards the passages.
- Misreading: the model combines or interprets the passages incorrectly.
- Off-topic answer: the answer is faithful to the context but does not address the question.
You measure these with faithfulness and answer relevance, which later chapters cover.
Why the two can hide each other
The final answer alone does not tell you where the fault is. Consider three cases for the same question.
| Case | Retrieved context | Answer | Fault |
|---|---|---|---|
| 1 | Lacks the fact | Wrong or "I don't know" | Retriever |
| 2 | Contains the fact | Contradicts the context | Generator |
| 3 | Lacks the fact | Correct, from model memory | Neither visible, but the answer is not grounded |
Case 3 is easy to miss. The answer looks right, so an end-to-end check passes. But the system is not using its documents, and it will fail on questions where the model's memory is wrong or outdated. This is why faithfulness (is the answer supported by the context?) is kept separate from correctness (is the answer true?).
A first diagnostic
You can separate the two failure types by asking two questions per example, in order:
- Did the retrieved context contain the information needed to answer?
- Given that context, did the generator produce a supported, relevant answer?
The sketch below turns those two yes/no judgments into a label. How to produce the judgments reliably is the subject of later chapters.
def classify_failure(context_has_answer, answer_is_supported_and_relevant):
if not context_has_answer:
return "retrieval failure"
if not answer_is_supported_and_relevant:
return "generation failure"
return "ok"
examples = [
(False, False),
(True, False),
(True, True),
(False, True),
]
for has_answer, good_answer in examples:
print(has_answer, good_answer, "->", classify_failure(has_answer, good_answer))The last example prints ok, even though the context lacked the answer. That is the case 3 problem from the table. To catch it, you also check that every claim in the answer is supported by the context, which is what faithfulness scoring does.
Common mistakes
- Judging only the final answer, which mixes both failure types into one score.
- Treating a correct answer as proof that retrieval worked.
- Changing the prompt to fix what is really a missing-passage problem.
Exercise
A user asks about a product's return window. The retrieved passages mention only shipping times, but the system answers "30 days," which is correct. Is this a retrieval failure, a generation failure, or both, and why does the correct answer not settle the matter?
Show answer
Both. Retrieval failed because the context lacks the return policy. Generation failed on faithfulness because the answer is not supported by the context, so it came from model memory or a guess. The answer happened to be correct, but it is ungrounded and will break when the model's memory is wrong or outdated.
Exercise
Which part of the pipeline should you check first when an answer is wrong, and why?
Show answer
The retriever. If the retrieved context does not contain the needed fact, changing the prompt or the model cannot produce a supported answer.