What is Query Rewriting?
Query Rewriting is a pre-retrieval transformation that converts a user's request and permitted context into one or more search-oriented queries while preserving the original intent, entities, constraints, and authorization scope.
Quick Facts
| Specification | Official Specification |
|---|
How It Works
Choose the Transformation by Failure Mode
Use conversational decontextualization for pronouns and omitted subjects, terminology normalization for aliases and versions, translation for a corpus-language mismatch, expansion for vocabulary gaps, and decomposition for independently retrievable facets. Multi-query retrieval runs several formulations and must deduplicate or fuse ranked results; [Query2doc](https://arxiv.org/abs/2303.07678) instead expands a query with generated pseudo-document text. HyDE, routing and reranking solve adjacent problems and should not all be labeled Query Rewriting.
Intent and Policy Contract
A rewrite record should include the original request, bounded conversation turns, rewriter and prompt revisions, output queries, language, purpose and trace ID. Preserve required entities, negation, units, versions and time bounds; ask for clarification when ambiguity cannot be resolved. Keep the original query as a retrieval baseline and reject candidates that invent facts or broaden scope. Never serialize authorization filters into free text: pass tenant, ACL, source and retention constraints unchanged to every retrieval branch.
Evaluation and Release Gate
The [Rewrite-Retrieve-Read paper](https://arxiv.org/abs/2305.14283) demonstrates that a learned rewriter can improve its evaluated downstream tasks, but those results do not prove rewriting helps every corpus. Run an ablation using original-only, rewrite-only and original-plus-rewrite retrieval. Measure Recall@k, MRR or nDCG, context precision, answer correctness and faithfulness, unanswerable handling, drift, latency and cost by query slice. Release only when end-to-end gains remain after reranking and when exact identifiers and already-good queries do not regress.
Key Characteristics
- Transforms user language into one or more retrieval hypotheses before search
- Supports decontextualization, normalization, translation, expansion, or decomposition
- Keeps the original request as the intent authority and comparison baseline
- Carries immutable authorization and source filters outside generated query text
- Can increase recall while reducing precision or adding request-path latency
- Requires retrieval and answer-level ablations because rewrite fluency is not quality
Common Use Cases
- Resolving a follow-up question from bounded conversation context
- Mapping product aliases and acronyms to terminology used by the corpus
- Generating complementary sparse and dense retrieval formulations
- Decomposing a multi-hop request into evidence-bearing subqueries
- Translating retrieval text while preserving names, numbers, versions and filters
Example
Loading code...Frequently Asked Questions
Is Query Rewriting the same as prompt rewriting?
No. Query Rewriting changes the text sent to a search or retrieval system while preserving the user's information need. Prompt rewriting changes instructions sent to a generative model. A RAG pipeline may use both, but they have different inputs, risks and evaluation metrics.
When should a RAG system avoid rewriting a query?
Avoid or bypass rewriting for exact identifiers, quoted phrases, already successful queries, latency-critical paths and requests whose ambiguity requires user clarification. Always compare against the original query; a fluent rewrite can remove the lexical signal that sparse retrieval needs.
What is semantic drift in Query Rewriting?
Semantic drift occurs when a rewrite changes the information need by adding assumptions, dropping constraints, altering negation or resolving an entity incorrectly. Detect it with entity and constraint checks, labeled intent judgments and end-to-end retrieval tests, then fall back to the original query or ask for clarification.
Should the original query be searched alongside rewritten queries?
Usually yes for multi-query retrieval because the original preserves exact user wording and acts as a safety baseline. Merge results with a documented method such as reciprocal-rank fusion or reranking, deduplicate documents, and measure whether extra branches improve recall without overwhelming the context with noise.
How should Query Rewriting be evaluated?
Use representative query-document judgments and compare original-only, rewrite-only and combined retrieval. Report Recall@k, MRR or nDCG, context precision, answer correctness and faithfulness, unanswerable behavior, drift rate, latency and cost. Break results down by follow-up, exact-ID, multilingual and multi-hop queries.