What is Query Rewriting?

Query Rewriting is the process of transforming a user's original question into one or more clearer, expanded, or retrieval-friendly queries before search.

How It Works

Query rewriting addresses a common RAG problem: users ask underspecified, conversational, or context-dependent questions, while retrieval systems need search-friendly terms. A rewrite step may expand acronyms, add missing entities from conversation history, split a complex request into subqueries, translate language, or normalize product names. The risk is semantic drift: an overactive rewrite can change the user's intent and retrieve confident but irrelevant evidence. Good systems log both the original and rewritten queries and evaluate whether rewrites improve grounded answers.

Key Characteristics

  • Improves retrieval by making implicit or ambiguous user intent more searchable
  • Can produce a single rewritten query or multiple focused subqueries
  • May use rules, an LLM, conversation history, metadata, or domain dictionaries
  • Carries semantic-drift risk if the rewrite changes the user's intent
  • Should be evaluated against retrieval quality and final answer grounding

Common Use Cases

  1. Expanding acronyms before searching technical documentation
  2. Resolving pronouns or follow-up questions using chat history
  3. Splitting a multi-part user request into separate retrieval queries
  4. Translating a query to match the language of the indexed corpus
  5. Normalizing product names, API versions, or internal terminology

Example

loading...
Loading code...

Frequently Asked Questions

Is query rewriting the same as prompt rewriting?

No. Query rewriting targets retrieval quality, while prompt rewriting usually targets model instruction clarity or output behavior.

When should a RAG system rewrite queries?

It is useful for follow-up questions, acronyms, vague wording, multilingual corpora, and complex requests that need multiple searches.

What is semantic drift in query rewriting?

Semantic drift happens when the rewritten query changes the user's intent, causing the retriever to fetch plausible but wrong evidence.

How can query rewriting be evaluated?

Compare retrieval recall, context precision, and answer grounding with and without rewriting on a representative query set.

Related Tools

Related Terms

Related Articles