JTjason.teixeira() Glossary
Home / Learn / Glossary / Query rewriting
RAG & Retrieval

Query rewriting

Query rewriting takes a user's raw question and rephrases it into something your retriever can actually find. The user types "why won't it charge," and you turn that into a clean query with the missing product name and context filled in. The catch: the rewrite happens before retrieval, so if it drops the wrong detail, every step after it works from the wrong question.

Why it matters

Real questions are messy. They are vague, full of pronouns, riddled with typos, or split across a chat where "that one" means something three messages ago. Vector search takes those words literally, so a bad phrasing pulls back junk and the model answers from junk. Query rewriting cleans the question up before it hits your index, which lifts context recall without touching the documents at all.

How it works

A small model rewrites the query first. Common moves: expand vague terms, resolve "it" and "that" from the chat history, fix spelling, or split one loaded question into several focused ones and retrieve for each. You measure it by checking whether retrieval improved. Run your golden set with and without the rewrite, then compare context recall and precision. If the rewritten query pulls the right chunks more often, it earns its place.

In practice

A user tells a support bot "still broken after the update, what now?" Searched as-is, that matches almost nothing useful. The rewriter uses the conversation to expand it into "checkout button unresponsive after version 4.2 update on Safari," which lands directly on the right troubleshooting doc. Same question, far better answer.

Want this checked on your own AI feature?
Get a free mini-eval — real findings on your live feature, no call required.
Free mini-eval →
© 2026 Jason Teixeira · Sage Ideas LLC · Glossary · Learn · privacy