Sub topic 3
Where single-shot retrieval breaks down
This chapter assumes you know basic Python, what a prompt and completion are, and how embeddings and vector similarity search work at a high level. It also assumes you have seen the classic retrieve-then-generate pipeline from the previous chapter.
The assumption built into classic RAG
The answer_with_rag function from the last chapter makes three fixed choices. It always retrieves. It uses the user's exact words as the query. It retrieves exactly once, with a fixed k. The model never gets to object to any of these choices.
That works when the question is self-contained and one passage answers it. Many real questions are not like that.
Common failure modes
| Failure | Example | What goes wrong |
|---|---|---|
| Unnecessary retrieval | "Thanks, that helps!" | The pipeline searches anyway and pastes unrelated chunks into the prompt. |
| Poor query | "And what about the limit for that?" | The follow-up has no meaning on its own, so the embedding matches nothing useful. |
| Multi-part question | "Compare the free and paid plan limits." | One query vector lands between two topics and may retrieve neither well. |
| Wrong source | A billing question sent to the API docs index | The search runs, but over the wrong collection. |
| Weak results | The top chunks are related but do not contain the answer | The model sees them and may guess instead of saying the evidence is missing. |
| Multi-hop question | "Which region hosts the service that the Pro plan uses for backups?" | The second search depends on what the first one finds. |
Each row has the same cause. The decision about what to retrieve is made before anyone has seen the question's difficulty or the first results.
A concrete case
Consider this question:
question = "Does the Pro plan's backup service support the region I chose earlier?"A single-shot pipeline embeds this sentence directly. The words "I chose earlier" refer to a previous message, so the vector carries little information. Even with a good query, the answer needs two facts: which service handles Pro backups, and which regions that service supports. The second fact cannot be searched for until the first is known.
Why tuning the pipeline only helps so far
You can improve classic RAG with better chunking, a reranker, a larger k, or a hybrid keyword and vector search. These help with weak results. They do not fix the structural problems:
- A larger
kadds noise for easy questions and still cannot perform a dependent second search. - A reranker reorders what was found. It cannot find what the query never reached.
- Query rewriting before the pipeline can fix vague follow-ups, but it is one more fixed step, applied to every question.
The pipeline is a fixed sequence. The questions vary.
What the model needs instead
Each failure above would be handled if the model could do the following:
- Decide whether to search at all.
- Write its own query.
- Choose a source.
- Read the results and decide whether they are enough.
- Search again, differently, if they are not.
That is the shape of an agent that uses retrieval as a tool. The next chapters build it step by step, starting with tool calling.
Exercise
A user asks, "Which database does the reporting service use, and what is its maximum connection count?" A classic RAG pipeline retrieves the top 4 chunks for this exact sentence and returns a wrong answer. Name two reasons from this chapter that could explain it, and one change that would address them.
Show answer
Possible reasons: the question has two parts, so one query vector may match neither well. It is also multi-hop, because the connection limit depends on first knowing which database is used. A fix is to let the model search first for the reporting service's database, read the result, then run a second search for that database's connection limit. Raising k alone would not solve the dependent second search.