ModelRefs / Query Rewriting — AI Glossary
Query Rewriting — AI Glossary
Transforming the user's raw query into a better-formulated retrieval query before searching the vector database. Three query-side techniques get conflated.
Overview
Query rewriting addresses ambiguous, conversational, or incomplete user queries that retrieve poorly. Techniques: rephrasing for keyword clarity, conversation condensation (merging history into one query), LLM-generated alternate forms. LlamaIndex's QueryTransform and LangChain's MultiQueryRetriever implement this pattern.
Reference details
| Topic | rag |
|---|---|
| Last reviewed | 2026-06-24 |
Related terms
How it works
- The incoming query is read together with the conversation, because a follow-up like 'what about the second one' has no retrievable content on its own.
- References are resolved against that history, producing a query that stands alone.
- The result is reformulated toward the corpus's register — a question becomes the declarative phrasing documents actually use.
- One query goes forward, replacing the original rather than joining it, which is the structural difference from expansion.
- The rewrite is logged, because when retrieval fails it is usually the rewritten query that was searched and not the one the user typed.
Example: The query that cannot be searched
Turn one: 'Compare the two storage tiers.' Turn two: 'Is the second one cheaper?' Embedded alone, the second query's content words are 'second', 'cheaper' — nothing that identifies a product, so similarity search returns essentially arbitrary chunks. Rewritten against the history it becomes 'Is the archive storage tier cheaper than the standard tier?', which has the terms the documents contain. No amount of reranking fixes the first version, because the information needed was never in the query.
Commonly confused with
Three query-side techniques get conflated. Rewriting *replaces* the query with a better-formed one — resolving "what about the second one" against the conversation, or turning a question into search-shaped text. Expansion *adds* terms or variants. Decomposition *splits* it into several queries. Rewriting is the one that fixes an under-specified or conversational query; the others fix a query that is clear but too narrow.
When to use it
Reach for it when:
- Conversational retrieval, where follow-ups are elliptical and depend on prior turns.
- User phrasing and corpus register differ enough that direct embedding retrieves poorly.
- Retrieval failures correlate with short or pronoun-heavy queries.
Reach for something else when:
- Queries are already self-contained, where a rewrite can only lose information.
- Recall is the problem rather than query form — expansion addresses that.
- The rewrite is not logged, leaving failures undiagnosable because the searched query is invisible.
Continue your research
Use these connected ModelRefs sections to compare alternatives, inspect implementation paths, and review the evidence and governance boundaries relevant to Query Rewriting — AI Glossary.
Frequently asked questions
What is Query Rewriting?
Transforming the user's raw query into a better-formulated retrieval query before searching the vector database.
What concepts are related to Query Rewriting?
Closely related concepts include query expansion, query decomposition, advanced rag.