Query rewriting sits at the front of modern RAG, semantic search, information retrieval, conversational search and vector search. A user asks one question; the retrieval system may search for another. It can perform query expansion, query reformulation, multi-query retrieval, conversational query rewriting, decomposition, synonym expansion or hypothetical-document generation so that the user’s language better matches the language of the indexed corpus. This often improves retrieval recall because people and documents rarely describe the same idea with exactly the same words.
The danger is equally fundamental. A rewritten query is a representation of the user’s intent, not the intent itself. If the rewriter resolves ambiguity incorrectly, deletes a negation, normalises a rare term into a common but different concept, assumes the wrong referent from conversation history, or converts a cautious question into a stronger claim, the retrieval system can search brilliantly for the wrong thing. Query rewriting in RAG is therefore lossy intent compression: the system trades the original linguistic form for a search-oriented representation and hopes the distinctions it removes were not the distinctions the user cared about.
This longform explains how query rewriting works, query expansion, multi-query RAG, HyDE, conversational retrieval, query decomposition, search intent, lexical and semantic mismatch, retrieval recall, ambiguity, negation, entity resolution, temporal constraints, filters, query drift, reranking and intent preservation. The core principle is simple: a rewrite should improve the route to evidence without quietly changing the destination.
Quick Read: What Is Query Rewriting?
Query rewriting transforms the user’s original query into a representation intended to retrieve better evidence.
The rewrite may be a cleaner version of the same question.
It may be several alternative searches.
It may split one complex request into subqueries.
It may add terms inferred from conversation history.
It may create a hypothetical answer-like passage and search for documents near that passage in embedding space.
One-sentence answer: query rewriting is lossy because the user’s original utterance is replaced or supplemented by search-oriented representations whose success depends on preserving the constraints, uncertainty and referents that made the original question what it was.
Why the User’s Words and the Corpus’s Words Differ
A parent asks about “kids forgetting what they studied”.
A research paper discusses retrieval failure, memory decay, interference and spacing effects.
A patient says “heartburn medicine”.
A medical database indexes proton-pump inhibitors and gastro-oesophageal reflux.
A programmer says “the page keeps remembering the old data”.
Documentation discusses caching and stale revalidation.
Retrieval must bridge vocabulary worlds.
Lexical Mismatch Is the Old Problem
Classical information retrieval has long dealt with synonymy and vocabulary mismatch.
A user searches “car”.
The relevant document says “automobile”.
Query expansion adds related vocabulary so lexical retrieval has more chances to connect the two.
The technique predates modern RAG.
Large language models simply make the rewriting machinery much more expressive.
Semantic Search Does Not Eliminate Rewriting
Dense embeddings reduce dependence on exact lexical overlap.
They do not solve every mismatch.
A short ambiguous query can still map to the wrong semantic neighbourhood.
Specialist terminology, dates, names, negations and hard filters can remain poorly represented.
Rewriting can add context before embedding so the query vector expresses a more useful intent.
Conversational Queries Are Often Incomplete Alone
A user asks:
What about the second one?
The sentence is meaningless without conversation history.
A conversational query rewriter might produce:
What are the side effects of the second medication discussed, metformin?
The rewrite restores a referent that the search index cannot infer from the isolated query.
Referent Resolution Is Powerful and Dangerous
If “the second one” actually referred to the second clinical trial rather than the second medication, the rewritten query becomes confidently wrong.
Conversation-aware retrieval therefore needs a distinction between resolved and unresolved references.
When ambiguity materially changes retrieval, preserving ambiguity can be safer than silently guessing.
Query Expansion Adds Possible Vocabulary
A query about “job burnout” might expand toward occupational stress, emotional exhaustion and workplace wellbeing.
This can increase recall.
It can also create drift.
Workplace wellbeing is broader than burnout. Occupational stress is related but not identical.
Every expansion term broadens the search frontier and risks pulling in documents that are semantically adjacent rather than actually responsive.
Multi-Query Retrieval Keeps Several Interpretations Alive
Instead of committing to one rewrite, a system can generate several.
- one literal query;
- one synonym-expanded query;
- one domain-specific reformulation;
- one broader conceptual query;
- one narrow exact-constraint query.
The candidate sets can then be merged.
This costs more retrieval work but protects against one bad interpretation dominating the entire pipeline.
Redundant Queries Are Insurance
From a pure efficiency perspective, five searches look wasteful.
From a recall perspective, they are alternative routes.
If one route drifts, another can preserve the relevant document.
The same principle appears throughout robust systems: redundancy is expensive until the primary path fails.
Query Decomposition Splits Composite Questions
Consider:
How did rainfall, housing policy and transport investment affect population growth in the town between 1990 and 2020?
One retrieval query may struggle to find documents covering all dimensions simultaneously.
A decomposition system can create subqueries for rainfall, housing, transport and population, then combine evidence.
The gain is coverage.
The risk is losing relationships among the subquestions.
Decomposition Can Destroy the Causal Question
The original question asked how several variables interacted to affect population growth.
Four independent searches can retrieve four piles of facts without retrieving evidence about interaction or causality.
A decomposition plan should therefore preserve a representation of the original composite relationship and return to it during synthesis.
HyDE: Search With a Hypothetical Answer
Hypothetical Document Embeddings, often called HyDE, generate an answer-like or document-like text from the query and embed that generated text for retrieval.
The intuition is clever.
A short user question may live far from the style of relevant documents in embedding space.
A hypothetical answer can resemble the language and structure of those documents more closely.
The retriever searches from the hypothetical document’s representation.
HyDE Can Hallucinate the Route
The hypothetical document need not be factually correct to help retrieval.
That is both its strength and danger.
If the generated text invents a plausible but wrong technical framing, the embedding can move toward a corpus neighbourhood that reinforces the invented framing.
The hypothetical document should be treated as a search instrument, never as evidence.
Negation Is Tiny and Expensive to Lose
“Treatments that improve survival” and “treatments that do not improve survival” share most of their vocabulary.
A rewrite that drops “not” can preserve topic and invert intent.
Negation should therefore be treated as a protected constraint rather than a low-information stopword.
Dates Are Hard Constraints, Not Decoration
“Current policy” is not the same query as “policy in 2019”.
“Before 2020” is not the same as “after 2020”.
A rewriter should preserve temporal operators explicitly and pass them into filters where possible.
Semantic similarity alone is often too soft for hard time constraints.
Names and Identifiers Should Resist Paraphrase
Product codes, legal citations, chemical names, aircraft variants, examination paper numbers and database IDs may look linguistically awkward.
They are often the most precise part of the query.
A helpful-sounding rewrite that replaces an exact identifier with a generic category can destroy retrieval precision.
Spelling Correction Can Correct the User Into the Wrong Entity
A rare surname, place, drug or technical term can resemble a common typo.
Automatic correction may transform the rare correct term into the common wrong one.
High-confidence correction should be distinguished from uncertain normalisation, especially when named entities drive retrieval.
Filters Are Part of the Rewrite
A user says “papers from the last two years”.
The best rewrite may not be a longer sentence.
It may be:
- semantic query: the research topic;
- metadata filter: publication date within the required range.
Hard constraints should often become structured filters rather than being entrusted to embedding similarity.
Search Intent Is a Constraint Set
Intent is not one hidden label such as informational, transactional or navigational.
For a retrieval system, intent can include:
- topic;
- entity;
- time;
- location;
- population;
- comparison target;
- polarity;
- desired evidence type;
- jurisdiction;
- granularity;
- exclusions.
A rewrite is faithful only if it preserves the constraints that matter to the receiver.
