query rewriting
In plain wordsRephrasing a user's question before searching — fixing typos, adding missing details, splitting it into simpler questions — so the search engine finds better results.
The transformation of a user's query into one or more queries better suited to a retriever before search is run. Classic forms are spelling correction, synonym and term expansion, and pseudo-relevance feedback, which adds terms from the top-ranked results of a first search. In LLM pipelines a model commonly rewrites a conversational follow-up into a standalone question by resolving references to earlier turns; generates several paraphrases and merges their results (reciprocal rank fusionreciprocal rank fusion, n.: A simple recipe for merging several ranked lists of search results: each result earns points according to how high it ranks in each list, and the totals decide the final order.); decomposes a multi-part question into sub-queries; abstracts to a broader 'step-back' question; translates the request into a structured query such as SQL or metadata filters; or writes a hypothetical answer to search with (HyDEHyDE, prop. n.: A search trick: ask an AI to write a made-up answer to the question first, then search for real documents that resemble that imagined answer.). Rewriting improves recallrecall@k, n.: A score for search systems: of all the right answers that exist, what fraction showed up in the top k results? Higher means fewer relevant items were missed. when users' wording differs from the documents', but adds latency and can drift from the user's intent, so the original query is often searched as well.
Query rewriting turned 'and the Berlin office?' into 'parental leave policy for Berlin office employees'.
Origin
Query reformulation and relevance feedback are long-standing IR techniques, notably J. J. Rocchio's feedback algorithm for Gerard Salton's SMART system (1971). With LLMs, Xinbei Ma and colleagues framed a rewrite–retrieve–read pipeline in 'Query Rewriting in Retrieval-Augmented Large Language Models' (arXiv, May 2023; EMNLP 2023), and rewriting became a standard RAG component.
Related
- HyDEHyDE, prop. n.: A search trick: ask an AI to write a made-up answer to the question first, then search for real documents that resemble that imagined answer.
- retrieval-augmented generationretrieval-augmented generation, n.: Giving an AI an open-book exam: before answering, it looks up relevant passages in a set of documents and bases its reply on them, often citing where each point came from.
- agentic RAGagentic RAG, n.: Retrieval in which the AI runs its own research: it decides what to search for, looks at the results, searches again if needed, and only then answers.
- reciprocal rank fusionreciprocal rank fusion, n.: A simple recipe for merging several ranked lists of search results: each result earns points according to how high it ranks in each list, and the totals decide the final order.
- information retrievalinformation retrieval, n.: The study and engineering of search: how to organize huge piles of documents so that the few that matter to someone's question can be found and ranked quickly. AI systems rely on it to look things up.
- semantic searchsemantic search, n.: Search that understands what you mean, not just the words you typed, so a search for 'cheap places to stay' also finds 'budget hotels'.
Sources
- Rocchio, J. J. (1971). Relevance feedback in information retrieval. In G. Salton (ed.), The SMART Retrieval System: Experiments in Automatic Document Processing. Prentice-Hall.
- Ma, X., Gong, Y., He, P., Zhao, H. & Duan, N. (2023). Query Rewriting in Retrieval-Augmented Large Language Models. Proceedings of EMNLP 2023: 5303–5315. aclanthology.org/2023.emnlp-main.322
Mentioned in
agentic RAGagentic RAG, n.: Retrieval in which the AI runs its own research: it decides what to search for, looks at the results, searches again if needed, and only then answers., GraphRAGGraphRAG, prop. n.: A way of letting AI answer questions about a big pile of documents by first turning them into a map of people, things and their connections, then using that map to find and summarize answers., HyDEHyDE, prop. n.: A search trick: ask an AI to write a made-up answer to the question first, then search for real documents that resemble that imagined answer.