Query Transformation

Authors 8 articles 92 min total read
Definition
Query transformation is the pre-retrieval stage of a Retrieval-Augmented Generation (RAG) pipeline where the user’s raw query is rewritten, expanded, abstracted, or decomposed before vector search runs, so the retriever finds documents that match meaning rather than just original phrasing.
Also called: query rewriting, query expansion, pre-retrieval enhancement

What query transformation is

A RAG system is only as good as the search step in the middle. If a user types a vague question, uses different vocabulary than the source documents, or asks something multi-hop, the vector search returns weak matches and the model answers from thin context. Query transformation is the fix — a small step that sits between the user’s input and the retriever, reshaping the question into one or more forms that are more likely to find the relevant passages.

Four families dominate the technique. Hypothetical Document Embeddings (HyDE) asks the model to draft an imagined answer first, then searches the vector store using that draft instead of the question itself. Multi-Query expansion generates several rewordings of the original question, runs each search, and merges the results. Step-Back Prompting zooms out, asking a more abstract version of the question to retrieve background concepts before drilling into specifics. Decomposition splits a complex multi-hop question into sub-queries that each get their own retrieval pass.

Each family targets a different failure mode. Short queries fail because they don’t carry enough signal — HyDE compensates by inventing the missing context. Ambiguous queries fail because one phrasing only hits one phrasing — Multi-Query covers more of the embedding space. Specific factual questions sometimes fail because the supporting concept lives in a different part of the corpus — Step-Back surfaces that context first. The choice depends less on which technique is “best” and more on which failure mode keeps showing up in production logs.

Each rewrite technique fixes one kind of retrieval failure, and every rewrite adds a call that can drift or invent. · More AI cheat sheets
  • HyDE, multi-query, and step-back prompting fix different failure modes — mismatch the technique to the query shape and the rewrite costs latency without buying recall.
  • Every rewrite pays three structural costs: an extra LLM call, drift that narrows what it tried to expand, and hallucinated content that grounds retrieval in fabricated text.
  • Production practice has moved from a fixed rewrite step to a router that decides, per query, whether to transform at all and which technique earns the latency budget.
  • Compound questions need decomposition and routing, not a single rewrite — RAG-Fusion merges the split queries’ results back into one ranked list.

How query transformation is used in practice

Most teams meet query transformation through a RAG framework rather than building it from scratch. According to LangChain Docs, the MultiQueryRetriever generates several query variants from a single user question and returns the unique union of their search results — making it close to a one-line addition on top of an existing retrieval setup. According to LlamaIndex Docs, the equivalent abstraction is HyDEQueryTransform paired with TransformQueryEngine, which wraps any retriever and applies the transformation transparently. Both patterns show up in production RAG chatbots, internal Q&A tools, and document search assistants where users phrase questions in their own words and the system has to find the right passage anyway. The transformation step is invisible to the user; only the better answers are.

Log both the original query and the transformed query (or queries) for every request from day one. When retrieval starts returning irrelevant results, you need to know whether the model invented a misleading rewrite or whether the embedding similarity itself was the bottleneck — and you can’t reconstruct that after the fact.

Reading query transformation in order: mechanism, build, judgment

Start with what query transformation is and how HyDE, multi-query, and step-back prompting improve RAG recall — it separates the three core rewrite strategies before any guide asks you to pick one. When users ask compound questions a single rewrite cannot cover, query decomposition and routing explains how splitting a question into sub-queries and fusing the results with RAG-Fusion recovers recall a single rewrite loses.

Before wiring anything into production, read the hard technical limits of query transformation — every rewrite pays a latency tax, and one failure mode matters more than the rest: a hypothetical document plausible enough to ground retrieval in fiction. With that ceiling in view, the LangChain build guide wires HyDE and multi-query into a working pipeline, and the HyDE vs. multi-query vs. step-back decision guide turns query shape into a routing rule instead of a guess.

MAX asks: 'Why not just always run HyDE — it can only help, right?' MONA answers: 'Every rewrite is a bet: an extra LLM call, a chance of drift, and a chance the document it invents doesn't exist.' — comic dialog.
Query transformation is a cost paid per query, not a free upgrade.

How query transformation differs from reranking and contextual retrieval

Two neighbours get folded into the same mental bucket, and each mixing sends debugging in the wrong direction.

Query transformation acts before retrieval, widening what gets found by rephrasing the question; reranking acts after retrieval, reordering what already came back. A transformation problem shows up as documents that were never retrieved at all; a reranking problem shows up as the right document buried at position eight. Query transformation also targets a different side of the pipeline than contextual retrieval: transformation rewrites the question, while contextual retrieval enriches the document side by prepending context to each chunk before it is ever indexed. One fixes what you ask; the other fixes what got stored.

That two-sided view also explains where production practice moved in 2026 — teams shifted from a fixed rewrite step to router-selected transformation that picks a technique per query instead of running the same one on everything.

When query transformation fits — and when it doesn't

ScenarioUseAvoid
Users ask short, vague, or conversational questions✅
Sub-200ms total latency budget per request❌
Corpus vocabulary differs sharply from user phrasing✅
Per-query cost must stay near zero❌
Multi-hop question answering on long technical documents✅
Highly structured queries (exact-match lookups, SQL-like filters)❌

Common questions about query transformation

Q: Should I run HyDE on every query by default? A: No — treat it as a routed choice, not a default. Production teams that ran HyDE always-on hit a recall trap on structured corpora and a latency tax on smaller models; selective routing is now the standard practice, reserving the rewrite for the query shapes it actually helps.

Q: Can a rewritten query change what the user is actually asking? A: Yes, and that is the deeper risk, not just latency. An LLM that rewrites a question before retrieval effectively answers a different question than the one typed, often without telling the user it happened — an accountability question worth weighing before shipping the rewrite silently.

Q: Is a failed query rewrite easy to catch before it reaches the retriever? A: Not automatically — a hallucinated HyDE document reads like plausible prose, so nothing flags it before it grounds retrieval in fabricated text. The three structural costs — latency, drift, and hallucination — stay silent until you measure recall directly, not the rewrite’s fluency.

Q: If I add query transformation, does the reranker score the original question or the rewritten one? A: The reranker should always score the original user query, not the rewrite — HyDE retrieves with the hypothetical document, but ranking still has to answer what the user actually asked. Reranking against the rewrite is a common pipeline mistake that quietly drifts relevance.

Part of the retrieval-augmented generation theme · closest neighbour: reranking. Coming to this from a software background? Start with the story: Debugging RAG Failures: Why Developers Need a New Diagnostic Model.

Sources

1

Understand the Fundamentals

User questions and indexed documents rarely use the same words, and that gap quietly destroys recall. Query transformation closes it by letting an LLM reshape the question before the retriever ever sees it.

2

Build with Query Transformation

These guides show how to wire HyDE, multi-query, and step-back prompting into a working RAG pipeline, and how to pick the right technique for the kind of questions your users actually ask.

4

Risks and Considerations

An LLM that rewrites queries can also amplify bias, hallucinate fictional documents, and silently change what the user was asking.