RAG
Query rewriting
Turn what the user typed into what the index can answer.
What it is and why it exists
Follow-ups (“and for the second one?”) don’t retrieve anything alone. Rewriting resolves references against the conversation, expands acronyms, splits multi-part questions, or generates several variants (multi-query) or a hypothetical answer to embed (HyDE).
Quick prototype
Concatenate the last user message with the previous one.
In production, at scale
A small fast model rewrites with the recent history into a standalone query (and optional sub-queries), results from variants are fused, and the rewrite is logged so retrieval failures can be debugged.
Vendors and tools
| LangChain MultiQueryRetriever / LlamaIndex query transforms | Rewriting, HyDE, decomposition |
|---|
On AWS: Bedrock Knowledge Bases query decomposition (query reformulation) option.
How it fails
- Rewriter changes the meaning
- Extra LLM call adds 300+ ms to every request
What the interviewer asks next
When is HyDE useful?
When questions and documents are phrased very differently: embedding a hypothetical answer lands nearer to real answers than the short question does.