Sub topic 12
Why Poor Retrieval Caps Grounding Quality
This chapter assumes you can read basic Python and JSON. It also assumes you have called an LLM API and know the outline of a retrieval-augmented generation (RAG) pipeline. You have seen how chunks get numbered, how the model is asked to cite them, and how code validates the markers. All of that work happens after retrieval. This chapter covers the step before it, and why that step sets the ceiling for everything after.
The ceiling idea
Grounding means the answer is supported by the sources the model was given. The model can only be grounded in what it receives. If the right passage never reaches the prompt, three outcomes are possible:
- The model abstains, which is correct but unhelpful.
- The model answers from its own memory, and the citations it adds are decoration.
- The model stretches a loosely related chunk into an answer it does not support.
Citation validation does not fix any of these. A marker like [2] can be perfectly valid, because source 2 exists, and still point at a chunk that does not contain the answer. The system is then well formed and wrong.
So retrieval quality is a cap. Better prompts, stricter validators and bigger models can bring you up to the cap, but they cannot raise it.
Common retrieval failures
Each failure below produces a different symptom in the cited answer. Recognizing the symptom helps you find the cause.
| Failure | What happens | Symptom in the answer |
|---|---|---|
| Recall miss | The relevant chunk is not in the top k results | Abstention, or an answer from model memory |
| Ranking error | The relevant chunk is retrieved but ranked low or cut off | Answer built from a weaker chunk |
| Bad chunk boundaries | The fact is split across two chunks, or the chunk lacks the context that makes it true | Partial answer, or a claim missing its condition |
| Near-duplicate chunks | Several versions of a document are retrieved | Conflicting claims, citations to outdated text |
| Semantic mismatch | The embedding matches topic but not the specific question | Plausible, on-topic, unsupported answer |
| Stale index | The source changed after indexing | Valid citation to text that no longer says that |
Recall misses
Recall is the share of relevant chunks that appear in the retrieved set. If the answer lives in one chunk and that chunk is not retrieved, nothing downstream can find it. This is the most damaging failure because the pipeline gives no signal. The prompt looks normal, and the model may produce fluent text anyway.
Ranking and truncation
Retrieval often returns more chunks than fit in the prompt, so you cut the list. If the relevant chunk sits at rank 8 and you keep the top 5, it is gone. Models also use long contexts unevenly. Facts placed in the middle of a long block are sometimes used less reliably than facts at the start or end. Keeping the context short and well ordered helps.
Chunk boundaries
A chunk is the unit you cite. If chunks are too small, a sentence like "This limit does not apply to paid plans" loses the sentence before it that names the limit. If chunks are too large, a single citation covers pages of text and tells the reader little. Neither extreme supports checking a claim.
Duplicates and staleness
If the index holds v1 and v2 of the same page, both can be retrieved. The model may merge them or cite the old one. Store version or date metadata with each chunk and, where it matters, filter to the current version before building the context.
Measuring retrieval before you measure citations
You can test retrieval alone, with no model involved. Build a small set of questions, and for each one label which source ids contain the answer. Then check whether those ids appear in the retrieved set.
The function below computes recall at k for a batch of questions. It assumes each question has a set of gold chunk ids, and that your retriever returns a ranked list of ids.
def recall_at_k(retrieved_ids, gold_ids, k):
"""Fraction of gold ids found in the first k retrieved ids. Returns None if no gold ids."""
if not gold_ids:
return None
top_k = set(retrieved_ids[:k])
return len(top_k & set(gold_ids)) / len(gold_ids)
def mean_recall_at_k(examples, k):
"""examples: list of dicts with 'retrieved' (ranked id list) and 'gold' (set of ids)."""
scores = [recall_at_k(e["retrieved"], e["gold"], k) for e in examples]
scores = [s for s in scores if s is not None]
return sum(scores) / len(scores) if scores else 0.0
examples = [
{"retrieved": ["a", "b", "c", "d", "e", "f"], "gold": {"b"}},
{"retrieved": ["x", "y", "z", "w", "v", "a"], "gold": {"a"}},
{"retrieved": ["m", "n", "o"], "gold": {"n", "p"}},
]
for k in (3, 5, 6):
print(k, round(mean_recall_at_k(examples, k), 3))Running this prints:
3 0.5
5 0.5
6 0.833The second example shows the trap. Its gold chunk sits at rank 6. With k set to 3 or 5 it is missed, so the answer to that question can never be grounded. The third example keeps a recall of 0.5 at every k because the retriever never returns chunk p. Raising k does not help there. That chunk needs a different fix, such as better chunking, query rewriting or hybrid search.
Notice that raising k improves recall but adds more text to the prompt. More context means more distractors, higher cost, and more room for the model to cite the wrong chunk. Choose k by measuring, not by guessing.
Detecting weak retrieval at run time
You usually do not have gold labels in production, but you can still collect signals that retrieval may have failed.
- Low similarity scores. If the best score is below a threshold you calibrated on real queries, the sources are probably off topic.
- Flat score distribution. If the top 10 scores are nearly identical, the retriever cannot tell which chunk matters.
- Empty results. Metadata filters can remove everything.
A simple guard can route these cases to the abstention reply instead of calling the model.
def retrieval_looks_weak(scores, min_top=0.35, min_gap=0.02):
"""scores: similarity scores sorted high to low.
Thresholds are placeholders. Calibrate them on your own queries and embedding model.
"""
if not scores:
return True
if scores[0] < min_top:
return True
if len(scores) > 1 and scores[0] - scores[-1] < min_gap:
return True
return False
print(retrieval_looks_weak([]))
print(retrieval_looks_weak([0.12, 0.10, 0.09]))
print(retrieval_looks_weak([0.61, 0.58, 0.40]))
print(retrieval_looks_weak([0.50, 0.50, 0.49]))This prints True, True, False, True.
Ways to raise the cap
These changes act on retrieval, not on the prompt.
- Improve chunking. Split on natural boundaries such as headings and paragraphs. Keep a small overlap between chunks so a sentence is not cut from its context. Prepend the document title or section heading to each chunk so it carries its own context.
- Combine search methods. Keyword search (such as BM25) finds exact terms like error codes and product names that embeddings sometimes blur. Dense embeddings find paraphrases. Merging both result lists often raises recall.
- Rewrite the query. Users write short or ambiguous questions. Expanding a follow-up like "what about the free tier?" into a self-contained query helps the retriever.
- Retrieve wide, then rerank. Fetch 30 candidates, score them with a stronger model that reads the question and chunk together, and keep the best 5. This improves ranking without adding to the prompt.
- Filter by metadata. Restrict by product, version or date before search when the question implies it.
- Keep the index fresh. Re-index when sources change, and store a content hash so you can detect stale chunks.
Each change should be judged by recall at k on your labeled set, not by looking at a few answers.
How retrieval failures interact with citations
A grounded-looking answer from poor retrieval is the hardest case to catch. Consider what each checker from earlier chapters can see.
| Check | Catches | Misses |
|---|---|---|
| Marker validation | Numbers outside the supplied range | A valid number pointing to an irrelevant chunk |
| Quote verification | A quote that is not in the cited source | A real quote that does not answer the question |
| Claim-support checking | A claim the cited chunk does not support | A true claim that the right chunk would have contradicted or qualified |
The last row matters. If the chunk that states an exception was never retrieved, the answer can be fully supported by the chunks you did retrieve and still be misleading. Support is judged against the context, not against the whole corpus. This is why retrieval evaluation is a separate step and cannot be replaced by citation checks.
A practical diagnosis routine
When a cited answer is wrong, work backward through the pipeline:
- Was the correct chunk in the corpus and indexed? If not, fix ingestion.
- Was it in the top k retrieved? If not, fix retrieval (chunking, hybrid search, query rewriting).
- Was it in the final context after truncation and reranking? If not, fix ranking or context budget.
- Did the model cite it? If not, fix the prompt or the abstention rule.
- Did the cited chunk actually support the claim? If not, add claim-support checking.
Most teams that start at step 4 and rewrite prompts find that the fault was in step 2 or 3. Checking in this order saves time.
Exercise
A retriever returns chunks ranked [c7, c2, c9, c4, c1, c8]. The only chunk that answers a question is c1. You assemble the prompt from the top 4 chunks. The model replies with a confident answer citing [2], and your marker validator reports no problems. What is the most likely cause of the wrong answer, and which metric would reveal it?
Show answer
The answer chunk c1 is at rank 5, so cutting to the top 4 removed it. The model had to answer from other chunks (here, citing source 2, which is c2), and the marker was valid because source 2 exists. Recall at k with k=4 would score 0 for this question, while recall at k=5 or higher would score 1. The fix is to improve ranking (for example, reranking) or raise k, and to measure the change on a labeled set.
Exercise
Your mean recall at 10 is 0.95, but users report answers that leave out important exceptions. Name two retrieval-side causes you would investigate.
Show answer
Likely causes include chunk boundaries that separate an exception from the rule it modifies, and context truncation or ranking that drops the chunk containing the exception before the prompt is built. Recall computed on one gold chunk per question can also hide the problem when the exception sits in a second chunk that was not labeled as gold. Labeling all relevant chunks and checking whether each reaches the final context would expose it.