Senior · 8 chapters
Query transformation
Rewriting, expansion, HyDE, multi-query, decomposition, routing
Transformation can recover recall from underspecified questions, but uncontrolled rewriting also adds latency, cost, and plausible-but-wrong retrieval paths.
Read these first
What you will know
Rewrite a bad user query into a good search query, then compare retrieval results against the original using a fixed corpus and relevance labels
A useful rewrite removes conversational filler without deleting constraints, entities, dates, or negations that determine relevance.
Implement multi-query and measure the recall gain
Report recall@k alongside added generation and retrieval cost, deduplication behavior, and any precision loss from merging more candidates.
Decompose a compound question into separately answerable parts
The parts need explicit dependencies and a merge strategy; independent retrieval can miss that one subanswer constrains another.
Run a HyDE comparison against the original-query baseline and inspect both recall and false-positive changes
A generated hypothetical answer supplies semantic vocabulary for sparse queries, but its invented details can steer retrieval toward evidence that merely sounds plausible.
Show a query that retrieval cannot serve until it is transformed
Queries with pronouns, implicit entities, multiple intents, or missing search terms expose failures that a clean benchmark question hides.
Chapters
- 1
A query naming nothing the index contains cannot be retrieved
Four separate things can be wrong with a question before retrieval runs: conversational filler wrapped around a real constraint, a referent that exists only in the previous turn, vocabulary the corpus never uses, and two intents packed into one sentence. Each calls for a different repair, and the wrong one leaves the query just as unretrievable. Here you build the diagnosis, including which defects are detectable from the query text alone.
- 2
An oracle query tells a bad question from a missing document
One broken query is a diagnosis; a failing population needs triage before anyone transforms anything. Sample the failures and establish the ceiling first: write a query out of the gold passage's own wording and see whether retrieval returns it. If even that misses, the evidence is absent, mis-parsed or unindexed, and no rewrite in the world reaches it. What survives gets sorted against the four defects, and kept apart from gold passages that ranked just below k and from answers generated poorly over passages that were correct. That partition is what turns 'transformation might help' into a size: the share of the failing population this layer can reach at all.
- 3
A rewrite that strips filler can strip the constraint too
'Hey quick one — for the 2023 filing, did we NOT have to restate Q3 revenue?' becomes 'restate Q3 revenue', and recall falls below sending the raw question. The year and the negation were constraints, not noise, so the shortened query now matches restatement discussion from every filing period. You compare rewritten against original on a fixed corpus with relevance labels, and learn which token classes a rewrite may never drop.
- 4
A follow-up turn must be rewritten into a standalone query
'Does that one cover weekends?' embedded as written returns generic weekend-coverage passages from every product, because the tier being referred to appears nowhere in the query's vector. The repair is a rewrite against conversation history that names the tier and the product outright. This chapter builds that step, settles how many turns it should read, and shows what it costs when it binds the referent to the wrong antecedent.
- 5
Recall over 41 candidates is not recall over 10
Five paraphrases retrieving top-10 each, deduped to about 41 chunks, moves reported recall from 0.61 to 0.84 — but that compares recall across 41 candidates against recall across 10, and most of the movement is pool size. Rerank the union back down to 10 and re-measure; the honest gain lands nearer 0.69. The chapter then prices the intervention: extra generation calls, retrieval fan-out, and precision lost by merging more candidates.
- 6
A hypothetical answer supplies vocabulary and invents specifics
HyDE raises recall@10 from 0.55 to 0.68 while sharply increasing passages that are on-topic but about the wrong product version, and a single mechanism explains both movements. The generated answer contributes the vocabulary the bare query lacked, and it also fabricates details such as version numbers that retrieval then matches. Setting temperature to 0 does not ground it — the invention just becomes the most likely one, turning intermittent bias into systematic bias.
- 7
The second sub-query cannot run until the first has answered
'Which EU enterprise accounts churned after the March price change, and what did their exit interviews say' splits into two parts where the second is unretrievable until the first yields an account list. Fired in parallel it decays into exit interviews from accounts that never churned. Decomposition therefore needs declared dependencies and a merge strategy, both built here — along with why paraphrasing a two-intent question never separates the intents it carries.
- 8
Route each transformation to the defect it repairs
Rewrite, then multi-query, then HyDE on every request tripled p95, quadrupled cost per query, and moved a 250-question eval by a single point, because transformation is a recall intervention and clean benchmark questions rarely fail for recall reasons. A six-point aggregate elsewhere is equally consistent with big gains on underspecified queries plus real losses on precise ones that got widened. Decide per query, and know the corpus where you refuse the layer outright.
External resources
- Precise Zero-Shot Dense Retrieval without Relevance Labels (HyDE)arxiv.org
Why generating a fake answer to embed beats embedding the question.
- Chapter 63: Query rewriting, HyDE, multi-query, query decomposition — The Holy Grailkunwar.page
A substantive explainer that covers the query-document gap and gives concrete mechanics, tradeoffs, and examples for expansion, HyDE, multi-query, decomposition, and conversational rewriting.
- MultiQueryRetriever referencereference.langchain.com
Working multi-query fan-out you can adapt to your own retriever.
- Query Transformationslangchain.com
Catalogs rewriting, expansion, decomposition and routing in one place.
- RAG from scratch: Part 5 (Query Translation -- Multi Query)LangChain
Short, code-first take on rewriting a query into several.
- Query Transformation: HyDE, Multi-Query & Decomposition in Retrieval Augmented GenerationYash Jain
Compares the three transforms on the same retrieval task.