Query rewriting
Query rewriting is the transformation of a query into an alternative formulation intended to better support its execution or retrieval while preserving its intended meaning or behavior.
AI Agents and Applications
Query rewriting is a technique that transforms an original search request into one or more clearer or more targeted queries to improve retrieval results.
- How it is used
- Improves web-search and RAG retrieval by turning unclear requests into search queries before results reach answer synthesis.
- How deep it goes
- Builds a prompt-to-LLM rewriter and a complete RAG chain, then extends generation to multiple parsed queries and retrieval.
- Examples
- Uses basketball-championship web searches and Cornwall travel questions retrieved from a vector store.
- What you can do after
- Build it from scratch with a LangChain rewriter chain, or apply MultiQueryRetriever to retrieve across alternative questions.
Read how AI Agents and Applications explains query rewriting →
AI-Powered Search
Query rewriting is the transformation of an original search query into an alternative query that preserves or enhances its intended retrieval behavior.
- How it is used
- Improves search recall, precision, and ranking by transforming parsed and enriched user queries before execution.
- How deep it goes
- Explains expansion, minimum matching, boosting, and engine translation, but stops short of evaluating rewrite quality.
- Examples
- Uses “vibranium” expansion, relatedness weights, minimum-match thresholds, boosts, and Solr query-tree transformations.
- What you can do after
- Builds rewritten search requests with related terms, matching constraints, ranking boosts, and engine-specific syntax.
Essential GraphRAG
Query rewriting is the transformation of a user query into a formulation that better matches the language and context of target documents.
- How it is used
- Improves RAG retrieval accuracy and recall when query wording fails to match relevant document language.
- How deep it goes
- Explains the terminology gap, names major strategies, and extends matching to summaries, paraphrases, and hypothetical questions.
- Examples
- Uses hypothetical document retrieval, step-back prompting, contextual summaries, paraphrases, and hypothetical question embeddings.
- What you can do after
- Apply it via hypothetical document retrieval or step-back prompting to improve document matching and retrieved-answer relevance.
The Art of AI Product Development
A retrieval technique that rewrites an input query into a form better suited to searching a target information collection.
- How it is used
- Improves retrieval precision when users submit vague or poorly structured questions to a retrieval-augmented generation system.
- How deep it goes
- Demonstrates rewriting, expansion, and classification through product examples without detailing implementation internals.
- Examples
- Uses broad AI-trend questions, SaaS and workflow-automation subqueries, and irrelevant healthcare or finance results.
- What you can do after
- Apply it by converting broad questions into focused subqueries and routing them toward relevant sources.
Read how The Art of AI Product Development explains query rewriting →
Grokking AI Applications
A technique that rephrases a user query to improve its semantic match with retrievable document content.
- How it is used
- Improves retrieval in RAG pipelines when users’ wording does not align with document phrasing.
- How deep it goes
- Explains the rationale, HyDE variant, translation use, and Langflow placement without detailing prompt design or evaluation.
- Examples
- Uses a thirsty-customer menu question, hypothetical answers, and English-to-Spanish query translation.
- What you can do after
- Apply it via Langflow by placing a Prompt Template and LLM between Chat Input and ChromaDB.
Read how Grokking AI Applications explains query rewriting →
Related concepts
- language modeluses · A language model is a computational model that represents patterns in linguistic tokens to estimate sequence probabilities and predict or generate language from context.
- step-back promptingincludes · Step-back prompting is a prompting technique that reframes a specific question as a broader, more abstract question before addressing the original question.
- HyDEincludes · HyDE is a retrieval technique that generates hypothetical document or answer content from a query and uses that content or its embedding to retrieve relevant documents.
- ruleimplemented by · A PostgreSQL rule is a query-rewrite definition attached to a database relation that modifies or adds statements when specified events occur.
- retrieval-augmented generationpart of · Retrieval-augmented generation is a technique that retrieves relevant information from external sources and supplies it as context to a generative model when producing an output.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.




