Glossary
What is query rewriting
In short
Query rewriting is a search step in which a language model rewrites the user’s question into a query that a search system can use well, before the search runs.
Search and RAG · query rewriting
MMOOZZGG.com editorsChecked: 1 min read
For a child
A little child says to Mom: “Where’s that thing, you know, the one that buzzes?” Mom understands and asks Dad: “Where’s the hair dryer?” Dad finds it at once. Mom turned an unclear question into a clear one. Query rewriting does the same for a computer: before searching, it turns a confused question into a clear, short one.
In plain words
People write questions as they think: with typos, pronouns, extra words and references to earlier messages. A search on such a phrase often misses. So before the search, a neural network rewrites the question. It removes what is extra, replaces “it” with the thing that was discussed, adds precise terms and sometimes splits a complex question into two simple ones. For example, in a chat a customer first asked about the Business plan and then wrote “and how many minutes does it have?”. The system then searches for “number of minutes in the Business plan”.
For business
This step is cheap and often has a visible effect in customer chats, where questions are short and rely on earlier messages. The costs are one short model call before each search and a small delay. The risk is that the model can distort the meaning: swap a term for a similar one, lose a contract number or drop a negation. So the rewritten query is saved to a log, and exact identifiers go to search unchanged. For conversational scenarios the step is almost a must. How it handles your requests shows in the log of an AI support agent during its first weeks of work.
For a specialist
Query rewriting belongs to pre-retrieval optimization. Ma et al. (2023) proposed the Rewrite-Retrieve-Read scheme instead of the usual Retrieve-Read: a language model first rewrites the input into a search query, then a web search engine returns the context, and a reader model answers. To align the query with a frozen retriever and reader, the authors train a small rewriter model with reinforcement learning, using the quality of the reader’s answer as the reward. In Corrective RAG (Yan et al., 2024), when internal results are poor, the input is rewritten into a keyword query for web search. Other forms are decontextualizing a dialog turn by resolving pronouns from the history, decomposing a complex question into sub-questions, expanding with synonyms (query expansion), generating several variants and then merging them as in RAG-Fusion, and a hypothetical document instead of a query as in HyDE. It is evaluated by retriever recall and the final accuracy of the answer.
Example
A bank customer writes “and if I pay late?” right after a question about a credit card. The system rewrites it as “penalty for late credit card payment” and finds the right clause in the fee schedule.
Related terms
Questions and answers
Sources
Where companies use it
Not sure whether your company needs this?
AI solutions map