Query Optimization
Query optimization for retrieval transforms a user's request into search inputs that are more likely to find relevant evidence. It can resolve references, expand terminology, decompose a question or generate a hypothetical passage, while preserving the original intent and testing whether the transformation actually improves retrieval.
What it is
A user's wording may not match the vocabulary or structure of an indexed collection. Query rewriting can express the same request using domain terms; expansion adds related search terms; decomposition creates subqueries for separate evidence needs. HyDE is a specific approach that generates a hypothetical answer-like document and embeds it as a retrieval query. These methods operate before or during retrieval rather than changing database execution plans, another meaning of query optimization. They can be implemented with rules or language models, and their output is a search representation, not verified evidence.
What the work involves
The practitioner records original and transformed queries, evaluates retrieved items against relevance labels and checks intent preservation. Transformation policies should preserve identifiers, dates, negation and other decisive constraints. Multiple query results need deduplication and a documented fusion rule. A direct-query baseline reveals whether the added call is worthwhile. Useful artifacts include the rewriting prompt or rules, examples of harmful rewrites and retrieval scores by question type. Generated hypothetical content should never be presented as a source that supports the final answer.
Illustrative example
A user asks why a particular machine keeps losing pressure after the evening cycle. A rewrite introduces the machine's documented term for the pressure-maintenance subsystem while preserving the evening condition and model identifier. A second query targets error logs. The system compares retrieved troubleshooting passages with those from the original request. If a rewrite drops the evening condition and retrieves a generic pressure fault, it is treated as a failed transformation despite returning many plausible documents.
Limits and common mistakes
Expansion can dilute a precise request, and a fluent rewrite can introduce a premise the user never supplied. Hypothetical documents may steer retrieval toward an imagined answer. Additional queries also consume latency and can inflate apparent recall by returning too much irrelevant material. Quality should be measured on the evidence ultimately used, with particular attention to rare terms and constraints. A transformation is valuable when it improves relevant retrieval while retaining the question's meaning.
Prerequisites
Query transformation modifies the retrieval query WITHIN a RAG pipeline — it requires understanding what retrieval is trying to achieve
Related skills
- → is part of: Retrieval-Augmented Generation
- → is part of: Semantic Search
Sources and further reading
- Precise Zero-Shot Dense Retrieval without Relevance Labels
Introduces HyDE and explains hypothetical-document representations for retrieval.
Last updated: 2026-10-10