Query Rewriting
Query rewriting transforms a user request into one or more retrieval queries. It is common in RAG systems because the user’s natural-language question is not always the best search query.
A rewriting function maps:
where is the current query, is conversation history, and is task state.
Rewrite Types
- Clarifying rewrite: make implicit references explicit.
- Decomposition: split a complex question into subqueries.
- Expansion: add synonyms, acronyms, or related concepts.
- Constraint extraction: turn a request into filters such as date, source, domain, modality, or entity.
- HyDE-style rewrite: generate a hypothetical answer or passage, then retrieve against it.
Risks
Query rewriting can improve recall but can also drift from the user’s intent:
The rewrite should be treated as a retrieval aid, not as a new task definition.
Checks
- Does the rewrite preserve the original task and constraints?
- Are filters extracted from evidence or invented?
- Is the rewritten query visible in logs or artifacts for debugging?
- Are multiple rewrites merged without flooding the context window?
- Is retrieval measured before and after rewriting?
- Can the system fall back to the original query?