Users ask short, vague, or vocabulary-mismatched questions. Query expansion rewrites or augments the query before retrieval to improve recall—complements hybrid search and re-ranking. It sits on the query side of the upcoming RAG pipeline.
Learning Objectives
By the end of this lesson, students should be able to:
- Define query expansion and list common techniques (synonyms, multi-query, HyDE).
- Explain how expansion trades recall gains for latency and noise.
- Implement a simple multi-query retrieve-and-fuse pattern.
- Contrast rule-based expansion with LLM rewriting.
- Guard against query drift that retrieves irrelevant topics.
- Evaluate expansion with recall@k on hard / short queries.
Query expansion improves retrieval by transforming a user query into one or more enriched queries (added terms, paraphrases, or hypothetical documents) whose search results are unioned or fused.
Technique Map
| Technique | Idea | Risk |
|---|---|---|
| Synonym / glossary | Add domain aliases | Static lists go stale |
| Multi-query | LLM paraphrases → multi search | Cost × N queries |
| HyDE | Embed a hypothetical answer | Hallucinated topic drift |
| PRF | Expand from top hits’ terms | Feedback loop on bad hits |
Helps
- Short queries
- Vocab mismatch
- Multi-intent asks
Hurts
- Already precise IDs
- Tight latency budgets
- Noisy corpora
Ops
- Cache rewrites
- Cap N paraphrases
- Fuse with RRF
Code: Multi-Query + RRF Fuse
Strengths
- Boosts recall on hard queries
- Cheap wins with glossaries
- Composes with hybrid + re-rank
Tradeoffs
- Extra latency / embed calls
- Drift retrieves wrong topics
- Harder debugging
“More paraphrases always help.” Past a point you retrieve a kitchen-sink of near-topic junk, burn tokens, and confuse the generator. Cap expansions, fuse ranks, and measure recall vs precision on a held-out set.
Knowledge Check
- Short Answer: What is query expansion? Answer: Enriching/rewriting the query to improve retrieval recall.
- True/False: HyDE embeds a hypothetical answer document. Answer: True (typically).
- Multiple Choice: Multi-query cost scales with: (a) number of rewrites searched, (b) CSS files, (c) DPI. Answer: (a).
- Short Answer: Name one drift risk. Answer: Expanded terms pull unrelated topics into the candidate set.
- True/False: Exact SKU lookups usually need heavy paraphrasing. Answer: False—often hurts.
- Multiple Choice: Fuse multi-query hits with: (a) RRF, (b) random delete, (c) only PNG. Answer: (a).
- Short Answer: What is PRF? Answer: Pseudo-relevance feedback—expand using terms from initial top hits.
- True/False: Expansion replaces the need for hybrid search. Answer: False—they complement.
- Multiple Choice: Next lecture: (a) RAG Pipeline, (b) Vol. 1 only, (c) printers. Answer: (a).
- Short Answer: How do you know expansion helped? Answer: Higher recall@k (without collapsing precision) on eval queries.
Key Takeaways
- Expand queries to fix vocabulary mismatch and short asks.
- Cap N, fuse with RRF, watch for topic drift.
- Eval on hard queries; skip expansion when exact match dominates.
- Next: RAG Pipeline.
Lab: Collect 15 failing short queries; add glossary expansion; measure recall@5 delta.
Prompt: Would you expand before or after metadata ACL filters? Why?
Recap: Query expansion is a recall lever on the question side. Continue with RAG Pipeline.