Sub topic 2
Why the user's question is often a poor search query
This chapter assumes you have built a basic RAG pipeline (index, retrieve, generate). It also assumes you know how embedding search and BM25 keyword search rank documents, and that you can read Python.
The assumption behind single-shot retrieval
A basic pipeline takes the user's text, passes it straight to the retriever, and keeps the top-k results. That works when the question looks like the passage that answers it. A question is written to be asked, though, and a passage is written to explain. The two often share few words and little structure.
The failures below account for most bad retrievals, and each calls for a different fix.
Failure mode 1: vocabulary mismatch
The user and the document describe the same thing in different words.
- The user asks "How do I get my money back?" The policy page says "refund eligibility".
- The user asks "app crashes on start". The troubleshooting guide says "launch failure".
BM25 only matches shared terms, so it misses these. Embeddings handle many synonyms, but they can still miss domain jargon, product codes, and abbreviations. Multi-query expansion and HyDE target this problem.
Failure mode 2: missing conversation context
In a chat, the latest message often cannot be understood alone.
user: Tell me about the Atlas plan.
assistant: Atlas is our mid-tier plan with 5 seats...
user: What about its pricing?The retriever receives "What about its pricing?" The word "its" points to nothing, so the search returns generic pricing pages. Conversational rewriting fixes this by producing "What is the pricing of the Atlas plan?" before retrieval.
Failure mode 3: a multi-part question
Some questions need several facts that live in different places.
"Which is cheaper for 20 users, Atlas or Borealis, and does either include SSO?"
A single embedding of this sentence blends four topics. It lands somewhere between them and may retrieve passages about none. Even a perfect search returns the top-k closest to the blend, not the top-k for each part. Decomposition addresses this, and multi-step retrieval handles the case where the second search depends on what the first one found.
Failure mode 4: wrong level of detail
Sometimes the question is too specific for the available text, or too broad.
- Too specific: "Why does error E-4012 appear on firmware 2.3?" Only a general chapter on error handling exists.
- Too broad: "How does billing work?" matches a hundred loosely related passages.
Step-back queries, which ask a broader question first, help with the first case. The second case usually needs a narrower query or a clarifying question.
Diagnosing a failure
Before adding any technique, look at what the retriever actually returned. Print the query and the top results for a failing question, then decide which mode applies.
def diagnose(query: str, results: list[str]) -> None:
print(f"QUERY: {query!r}")
for rank, passage in enumerate(results, start=1):
print(f"{rank}. {passage[:80]}")
diagnose(
"What about its pricing?",
["Pricing overview for all products", "Refund policy", "Contact sales"],
)The table maps the symptom you see to the likely cause.
| Symptom in the results | Likely cause | Technique |
|---|---|---|
| Relevant page exists but is absent or ranked low | Vocabulary mismatch | Multi-query, HyDE |
| Results are generic or off-topic in a chat | Missing context | Conversational rewriting |
| Results cover only one part of the question | Multi-part question | Decomposition |
| Results are too narrow or too broad | Wrong level of detail | Step-back, narrower query |
Key points
- A good question and a good search query are different things.
- Four common causes are vocabulary mismatch, missing context, multi-part questions, and wrong level of detail.
- Inspecting real retrieval results tells you which cause you have.
Exercise
A user asks, after discussing the Atlas plan, "Does it support SSO?" The retriever returns passages about SSO for several unrelated products. Which failure mode is this, and which technique fits?
Show answer
Missing conversation context. "It" does not identify the Atlas plan, so the search matches SSO in general. Conversational (standalone) rewriting fixes it by turning the question into "Does the Atlas plan support SSO?" before retrieval.
Exercise
A query is "Compare the refund rules and the shipping times for international orders." Why might one embedding search perform poorly, and what would you try?
Show answer
The query mixes two topics, refunds and shipping, so its embedding sits between them and may match neither well. Decompose it into two sub-questions, search each separately, and combine the results.