Sub topic 1
Recap: Single-Shot Retrieval and Where It Stops Working
Prerequisites
This chapter assumes you know the following:
- The basic retrieval-augmented generation (RAG) pipeline: index documents, retrieve passages, generate an answer from them.
- What embeddings are, and how vector search and keyword search (BM25) differ.
- How to call a large language model (LLM) with a text prompt.
- Enough Python to read short functions.
The single-shot pipeline
Single-shot retrieval means one query goes to the index once, and whatever comes back is all the model sees. The steps are:
- Take the user's question as typed.
- Turn it into a query. For vector search, this means embedding it. For BM25, it means tokenizing it.
- Fetch the top-k passages, ranked by score.
- Put those passages in the prompt and generate an answer.
Top-k and ranking
The value k is how many passages you keep. A small k keeps the prompt short and cheap, but the right passage may fall outside it. A large k raises the chance that the right passage is included, but it adds noise and cost, and the model may overlook relevant text buried in a long context.
Ranking decides which passages make the cut. Vector search ranks by similarity between the query embedding and each passage embedding. BM25 ranks by how many query terms a passage contains, weighted by how rare those terms are. Either way, the quality of the ranking depends heavily on the query text you send.
Here is a minimal sketch of the whole flow. The search and llm arguments are placeholders for your own index and model client.
from typing import Callable
def single_shot_answer(
question: str,
llm: Callable[[str], str],
search: Callable[[str, int], list[str]],
top_k: int = 5,
) -> str:
passages = search(question, top_k)
context = "\n\n".join(passages)
prompt = (
"Answer the question using only the passages below.\n\n"
f"Passages:\n{context}\n\nQuestion: {question}"
)
return llm(prompt)Notice that question is used twice: once as the search query and once in the final prompt. Single-shot retrieval treats these as the same thing. The rest of this tutorial rests on the idea that they should often be different.
Where it stops working
Single-shot retrieval works well when the question is self-contained, uses the same vocabulary as the documents, and has its answer in one place. It tends to fail in three common ways. The next chapter treats each in detail. Here is a preview.
| Failure | Example | Why one search fails |
|---|---|---|
| Vocabulary mismatch | "Can I get my money back?" against a document titled "Refund policy" | The query and the document share few words, and embeddings may not bridge the gap. |
| Missing context | "What about its pricing?" after a chat about a product | The query has no product name, so the search has nothing to match. |
| Multi-part question | "How does plan A differ from plan B on storage and support?" | The answer spans several passages, and one query may match only one of them. |
In each case the retriever did what it was asked. The problem is that the query was a poor stand-in for the information need.
Why this matters for the answer
A retrieval miss is hard to see from the outside. The model still receives passages, just the wrong ones. It then either answers from weak evidence or fills the gap from its own memory. The output reads fluently either way, so the error is easy to miss.
What comes next
The remaining chapters keep the same pipeline but add steps around the search call. Some steps rewrite the query before retrieval. Some run several searches and merge the results. Some retrieve over multiple rounds, using what was found to decide what to look for next. Each adds model calls, so each adds latency and cost. The final chapters cover how to measure whether that trade is worth it.
Exercise
A user asks "How do I reset it?" right after discussing a router model in a chat. The single-shot pipeline above searches with that exact text. Name the failure, and say what the search is likely to return.
Show answer
This is missing conversation context. The query has no subject, so "it" matches nothing specific. The search will likely return generic passages about resetting things (passwords, accounts, devices) rather than the router's reset steps, and the model will answer from the wrong evidence.