Query rewriting
Turning a messy or conversational request into better search queries before retrieval, while preserving what the user actually meant.
See it
What it is
Query rewriting turns a user's request into one or more search-friendly queries before retrieval. It can resolve pronouns from chat history, spell out an acronym, split a compound question, or add a likely synonym while leaving the final answer to a separate model step.
Reach for it when real users ask short follow-ups like 'what about the pro plan?' or use vocabulary that does not appear in the documents. Searching the original query alongside a few rewrites is usually safer than betting everything on one generated replacement, and Reciprocal Rank Fusion can merge the result lists without comparing incompatible scores. HyDE, from the 2022 paper 'Precise Zero-Shot Dense Retrieval without Relevance Labels', pushes the same idea further by embedding a hypothetical answer instead of the question.
Gotcha: a rewrite can become a confident guess. Product IDs, quoted phrases, dates, names, and negations must survive unchanged, or retrieval answers a cleaner question the user never asked. Log the original and rewrites, cap their count, and evaluate retrieval recall rather than judging how fluent the rewritten sentence sounds.
Ask AI for it
Build a query-rewriting stage for this RAG pipeline with the OpenAI Responses API. Generate at most three standalone rewrites, preserve quoted text, names, dates, negations, error codes, and product IDs exactly, embed the original plus every rewrite with text-embedding-3-small, retrieve each list independently, and merge them with Reciprocal Rank Fusion. Log all queries and add recall-at-10 tests against the existing golden dataset.