Query Rewriting
What is query rewriting?
Query rewriting transforms a user's request into one or more queries that a retrieval system can search more effectively. The rewritten query may clarify ambiguous terms, add missing context, expand abbreviations, remove conversational wording, or split a complex question into smaller searches.
The goal is to improve retrieval while preserving the user's real intent.
How it works
Suppose a user asks, “What changed after the last update?” That question depends on context. A system might rewrite it as “Changes in the refund policy after the July 2026 update” using the current conversation and selected product.
Common approaches include:
- replacing pronouns with explicit entities;
- expanding synonyms and abbreviations;
- adding domain or time constraints;
- generating multiple alternative queries;
- decomposing a multi-part question;
- translating a request into the index's language.
The rewritten queries then enter the retrieval pipeline.
Query rewriting versus retrieval
[Retrieval](/glossary/retrieval/) searches an information source and returns candidates. Query rewriting prepares the search request before that step. It does not retrieve documents itself.
Query rewriting also differs from reranking. Rewriting changes the query used to find candidates; reranking reorders candidates after retrieval.
Risks and failure modes
A rewrite can silently change meaning. Adding the wrong product, date, or assumption may retrieve convincing but irrelevant evidence. Expanding a query too broadly can increase noise, while making it too narrow can hide useful results.
For high-stakes requests, the system should preserve the original query, record the rewrite, and ask for clarification when the missing information cannot be safely inferred.
Practical design
A retrieval system can generate several rewrites and combine their results. This improves coverage but adds latency and duplicated candidates. Metadata filters can enforce known constraints such as region or access permission more reliably than inserting those constraints only as text.
Evaluation should compare whether rewriting improves the presence and ranking of the required evidence, not only whether the final answer sounds better.
Why it matters
Users speak conversationally, while indexes often work best with explicit search intent. Query rewriting bridges that gap and can materially improve sparse, dense, and hybrid search.
It should remain a transparent transformation, not an opportunity for the model to invent intent. Strong systems keep the original request, expose important assumptions, and fall back to clarification when the rewrite is uncertain.