Sub topic 3
Where single-shot retrieval breaks down
What this chapter assumes
You should know basic Python and what a prompt and a completion are. You should also know how embeddings and vector similarity search work at a high level, and how a retrieve-then-generate (classic RAG) pipeline is wired. The previous chapter showed that pipeline. This chapter explains where it fails, so the rest of the tutorial has a reason to exist.
The shape of the pipeline
In classic RAG, the code decides everything about retrieval. It embeds the user's message, fetches the top k chunks, pastes them into a prompt, and calls the model once. The model's only job is to write the answer from whatever arrives.
That design is simple, cheap and predictable. It is also rigid in three ways:
- Retrieval always runs, even when it is useless.
- Retrieval runs exactly once, with the user's literal words as the query.
- The model cannot inspect the results and ask for something better.
Every failure below follows from one of these three properties.
Failure modes
Retrieval that should not happen
A greeting such as "thanks, that helps" or a general question such as "what is a JSON object?" still triggers a search. The top k chunks are then the least-bad matches, which are irrelevant. They cost tokens and latency. Worse, the model may treat them as evidence and weave them into the answer. A threshold on similarity score helps a little, but scores are not calibrated across queries, so a fixed cutoff is either too strict or too loose.
The user's words are a poor query
Users write conversationally. A follow-up such as "and what about the Pro one?" has no meaning without the earlier turns, yet an embedding of that sentence is what gets searched. Other common mismatches:
- The question uses different vocabulary from the documents ("cancel" versus "terminate a subscription").
- The question contains filler that dilutes the embedding.
- The question names an error message or identifier that dense embeddings represent poorly.
A pipeline can add a rewriting step before search, but that is already a step the model performs. Chapter later in this plan covers rewriting as a decision the model makes.
Questions that need more than one lookup
Some questions cannot be answered by one query, because the answer sits in several places or because the second lookup depends on the first.
- Comparison: "How does the Basic plan differ from Pro on limits and price?" One embedding blends both plans and both topics. The top k may fill up with chunks about one plan.
- Multi-hop: "How much does the plan with the higher rate limit cost?" You must first find which plan has the higher limit, then look up its price. The second query does not exist until the first result is read.
Increasing k does not fix this reliably. The price chunk may rank below k chunks about rate limits, and a bigger k adds noise and cost to every request, including the easy ones.
The wrong source
Real systems often hold several stores: product docs, a ticket history, a SQL database, a policy wiki. Single-shot RAG searches whichever index the developer wired in. A question about last week's outage needs the ticket history, but the pipeline queries the docs and returns plausible, outdated text.
Weak results and no second try
Suppose the top results are only loosely related. A single-shot pipeline cannot notice this and try again. The model receives them and has two bad options: answer from weak evidence, or say it does not know. The prompt in the previous chapter asks for the second, but a model that sees topical text often answers anyway. Nobody checked whether the retrieved text actually answers the question.
A fixed k for every question
A fixed k is a compromise. A narrow factual question wants two chunks. A broad summary wants ten. Using four for both under-serves one and over-serves the other.
A concrete demonstration
This script uses a tiny keyword-overlap retriever so the result is deterministic and needs no libraries. The behavior it shows, a multi-hop question failing on the first query, is the same one dense retrieval produces on real data.
import re
DOCS = [
{"id": "d1", "text": "The Pro plan allows 600 requests per minute."},
{"id": "d2", "text": "The Basic plan allows 60 requests per minute."},
{"id": "d3", "text": "Pro costs 49 dollars per month."},
{"id": "d4", "text": "Basic costs 9 dollars per month."},
{"id": "d5", "text": "Refunds are available within 30 days of purchase."},
]
def tokens(text):
return set(re.findall(r"[a-z0-9]+", text.lower()))
def search(query, k=2):
q = tokens(query)
scored = [(len(q & tokens(d["text"])), d) for d in DOCS]
scored = [pair for pair in scored if pair[0] > 0]
scored.sort(key=lambda pair: pair[0], reverse=True)
return [d for _, d in scored[:k]]
question = "How much does the plan with the higher rate limit cost?"
first = search(question)
print("single-shot:", [d["id"] for d in first])
# single-shot: ['d1', 'd2'] -> both rate-limit chunks, no price
# A second query only makes sense after reading the first result:
second = search("Pro costs per month")
print("second hop:", [d["id"] for d in second])
# second hop: ['d3', 'd1'] -> the price chunk d3 is now presentThe first query returns only rate-limit chunks. The price chunk d3 scores zero because the question says "cost" and the document says "costs". Even if it had scored, the retriever could not know that "Pro" is the right plan until someone reads d1 and d2. A single pass cannot do that. A loop can.
Summary of failures and what addresses them
| Failure | Cause | What a model-driven loop can do |
|---|---|---|
| Needless retrieval | Search always runs | Skip search for greetings and general knowledge |
| Poor query | User's words used verbatim | Rewrite into a short, self-contained query |
| Multi-part or multi-hop question | One query, one pass | Decompose, search several times, use earlier results |
| Wrong source | One hard-wired index | Pick a source per query |
| Weak results | No check on results | Grade results, re-query, or admit the gap |
| Fixed k | Chosen by the developer | Request more or fewer passages per call |
What single-shot still does well
Do not read this chapter as an argument against classic RAG. It has real advantages:
- Latency is one retrieval plus one model call.
- Cost per question is nearly constant and easy to forecast.
- Behavior is easy to debug, because there is one query and one set of chunks to inspect.
- There is no loop that can run away or be steered by retrieved text.
If your questions are mostly single-fact lookups over one well-built index, single-shot RAG is often the right choice. The cases above are the signal to consider something else. Look for them in your logs: follow-up questions with missing context, answers that cite plausible but wrong chunks, and users who rephrase the same question three times.
How to diagnose which failure you have
Before changing architecture, sort a sample of bad answers by cause. A short checklist:
- Print the exact query sent to the retriever. If it is a fragment like "what about the Pro one?", the query is the problem.
- Print the retrieved chunk ids. If the needed chunk is absent, check whether it exists in the index at all.
- If the chunk exists but ranks below k, you have a ranking or multi-part problem.
- If the needed chunk is in the prompt and the answer is still wrong, retrieval is not the problem. Look at the prompt and the model.
Steps 1 and 3 point toward model-driven rewriting and decomposition. Step 2 may point to ingestion or source routing. Step 4 is outside this tutorial's scope.
Exercise
A user asks "Which of your two plans has the larger storage quota, and is it available in the EU region?" You run single-shot RAG with k=4 over one docs index. Name two distinct reasons the answer might be wrong even though the index contains every needed fact, and say what a loop could do differently for each.
Show answer
First, the question has two parts (storage quota and EU availability) but produces one embedding, so the four chunks may all be about storage and none about regions. A loop could decompose it and search twice. Second, the second part depends on the first: "it" refers to whichever plan has the larger quota, which is unknown until the quota chunks are read. A loop could read the first result, identify the plan, and then search "EU region availability for <plan>". A third acceptable answer: the facts may sit in different sources, and a loop could route each query to the right one.