Sub topic 1
Recap: Single-Shot Retrieval and Where It Stops Working
Prerequisites
Assume you know the basic retrieval-augmented generation (RAG) pipeline: documents are indexed, a user query is searched against that index, and a language model generates an answer from the retrieved passages. You should also know that vector search compares embeddings, while BM25 compares words and their frequencies.
Single-shot retrieval
Single-shot retrieval sends the user's question to a search system once. The system returns the top-k documents, where k is the number of results requested.
This approach is simple and fast. It works well when the question uses the same vocabulary as the indexed documents and contains all required context.
Why the user's question is often a poor search query
A user question is written for communication, not retrieval. It may contain:
- Pronouns with unclear references, such as “What about its price?”
- Informal terms that differ from the documents' terminology.
- Several questions joined together.
- Assumptions that are obvious in the conversation but absent from the final message.
For example, after discussing a product, “Does it support teams?” may retrieve weak results because “it” does not identify the product. A search system also cannot reliably infer whether “teams” means team accounts, group permissions, or collaboration features.
A failed search can therefore reflect a poor query rather than missing information.
Query rewriting in the pipeline
Query rewriting transforms the user's question into one or more search-ready queries before retrieval. The rewritten query should preserve names, constraints, and the user's intent.
The rewriter can condense a follow-up into a standalone question. It may also create multiple variants, broaden the wording, or split a complex request into sub-questions. These methods improve recall, but each model call adds latency and can introduce incorrect terms or details.
def condense(history, follow_up, llm):
if not history:
return follow_up
transcript = "\n".join(f"{role}: {text}" for role, text in history)
prompt = (
"Rewrite the final question as a standalone search query. "
"Keep names and constraints. Return only the query.\n"
f"{transcript}\nuser: {follow_up}"
)
return llm(prompt).strip()Exercise
Why can “What about its pricing?” fail in a single-shot retriever?
Show answer
The query contains an unresolved pronoun. Without conversation context, the retriever does not know what “its” refers to.