liveBook · Manning

Query rewriting

Also called query reformulation

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.

How 7 Manning books explain it

Build an Advanced RAG Application (From Scratch)

A query rewriter is a component that reformulates user queries to clarify references, expand terminology, and add appropriate specificity without inventing constraints.

How it is used
Improves RAG retrieval by making routed user queries semantically precise before vector search.
How deep it goes
Provides LLM prompt rules, conversation-history handling, concrete transformations, and unified-pipeline placement; it does not alter index or embedding internals.
Examples
Uses Q3 revenue, Uber and Lyft comparison, and AWS Lambda scaling-and-timeout requests to demonstrate clarification.
What you can do after
Build it from scratch as an LLM-based rewriter that preserves intent and feeds optimized queries into a routed retrieval pipeline.

Read how Build an Advanced RAG Application (From Scratch) explains query rewriting →

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 transforming user requests into queries better suited to search.
How deep it goes
Builds single-query and multi-query chains, integrates retrieval and answer synthesis, and discusses ranking and search latency.
Examples
Uses championship web searches and Cornwall travel questions to demonstrate alternative queries and retrieval.
What you can do after
Apply it via LangChain and ChromaDB to rewrite questions, retrieve context, and preserve original questions for answer synthesis.

Read how AI Agents and Applications explains query rewriting →

Retrieval Augmented Generation, The Foundational Ideas

Query reformulation is the transformation of an existing search query into an alternative formulation intended to retrieve more suitable information.

How it is used
Improves retrieval by translating, expanding, or revising queries when wording, relevance, ambiguity, or missing information limits the first search.
How deep it goes
Covers keyword conversion and iterative reformulation with a short implementation pattern, but defers detailed rewrite-model training.
Examples
Uses a Company Y director lookup, an outdated sanctions database, and a bounded Python agentic retrieval loop.
What you can do after
Apply it via an OpenAI-based agentic RAG loop that retrieves, evaluates, reformulates gaps, and stops after a bounded number of iterations.

Read how Retrieval Augmented Generation, The Foundational Ideas 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.

Read how AI-Powered Search explains query rewriting →

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.

Read how Essential GraphRAG explains query rewriting →

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 →

Also covered in

What to know first

Related concepts

Questions about query rewriting

What is 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.

Which Manning books explain query rewriting?

Build an Advanced RAG Application (From Scratch), AI Agents and Applications, Retrieval Augmented Generation, The Foundational Ideas, AI-Powered Search, Essential GraphRAG, The Art of AI Product Development and Grokking AI Applications.

What should I know before learning query rewriting?

Manning books that teach query rewriting usually introduce language model, retrieval-augmented generation, similarity search and embedding first.

What kinds of query rewriting are there?

Kinds of query rewriting include step-back prompting and HyDE.

What is query rewriting also called?

Query rewriting is also called query reformulation.

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.