Sub topic 12
Why Poor Retrieval Caps Grounding Quality
This chapter assumes you know basic Python, have called an LLM API, and understand the retrieve-then-generate flow of a RAG pipeline. It explains why the generator can never be better grounded than the passages it receives, and how to spot retrieval problems before you blame the prompt.
The ceiling
A model that cites sources can only cite what you put in the prompt. If the passage that answers the question was never retrieved, no prompt can produce a correct, supported answer. The best outcome is an abstention. The worst is a fluent answer that cites a nearby but irrelevant chunk.
So citation quality has an upper bound set by retrieval. Validating markers (covered in other chapters) tells you whether a citation points to a real source. It does not tell you whether the right sources were retrieved.
Common retrieval failures
| Failure | What the model sees | Typical result |
|---|---|---|
| Answer chunk not retrieved | Only related text | Abstention, or a guess with a misleading citation |
| Chunk split mid-fact | Half of a statement | Partial or distorted answer |
| Too many near-duplicates | Several copies of one source | Wasted slots, other evidence crowded out |
| Outdated document ranked first | Old value | Confident, correctly cited, wrong answer |
| Top-k too small | Truncated evidence | Missing second half of a multi-part answer |
The fourth row matters most. A citation can be valid and the answer still wrong, because the cited source itself was the wrong one to retrieve.
Measure retrieval separately
Check retrieval on its own before you test generation. For a set of questions where you know which source holds the answer, compute whether that source appears in the top k results (often called recall at k).
def recall_at_k(retrieved_ids, gold_ids, k):
"""Fraction of gold source ids found in the first k retrieved ids."""
if not gold_ids:
return 1.0
top = set(retrieved_ids[:k])
return len(top & set(gold_ids)) / len(gold_ids)
examples = [
{"retrieved": ["doc3", "doc7", "doc1"], "gold": ["doc1"]},
{"retrieved": ["doc2", "doc9", "doc4"], "gold": ["doc5"]},
]
for k in (1, 3):
scores = [recall_at_k(e["retrieved"], e["gold"], k) for e in examples]
print(k, sum(scores) / len(scores))With these examples, k=1 gives 0.0 and k=3 gives 0.5. The second question fails at every k, so no change to the prompt can help it. The fix belongs in chunking, the embedding model, query rewriting, or the index.
Practical diagnosis
When an answer is poorly grounded, work backward:
- Print the retrieved chunks for the failing question.
- Check whether any of them contains the answer.
- If none does, fix retrieval. Try different chunk sizes, add overlap, combine keyword and vector search, or rewrite the query.
- If one does, the problem is in prompting or generation. Inspect the prompt and the model output.
Trade-offs when raising k
Increasing k improves recall but adds noise, costs tokens, and gives the model more irrelevant text to cite from. Instructions placed inside irrelevant chunks also become more likely to reach the prompt. A reranker that scores the top 20 to 50 candidates and keeps the best 3 to 5 usually beats a large raw k.
Exercise
A user asks about a refund window. Your retriever returns five chunks about shipping policy, and the model answers with a refund period cited to chunk [2], which mentions "returns shipped within 14 days". The marker passes validation. What is the most likely root cause, and where should you fix it?
Show answer
Retrieval most likely missed the refund policy chunk, so the model built an answer from a loosely related passage. Marker validation passes because [2] exists. Fix retrieval (chunking, hybrid search, query rewriting, or reranking), check recall at k on a labeled question set, and rely on abstention when no retrieved chunk addresses the question.