Query rewriting changes the representation of a request before retrieval so that the search system can find more useful evidence. A user's natural-language question may contain ambiguous references, unfamiliar abbreviations, unnecessary wording, or several independent information needs. A rewriting layer converts that request into search-oriented text or structured queries while preserving its intent and constraints. In retrieval-augmented generation, the objective is better supporting context for the answering model, not a more polished version of the user's wording.
Common techniques include deterministic preprocessing, terminology normalization, conversational reformulation, query expansion, and decomposition. For example, after a user asks about database backups, the follow-up question “How long are they kept?” can become a standalone query about backup retention for the previously identified database. The rewriting component must retain the correct database, environment, and time period. If those details are missing or genuinely ambiguous, asking for clarification can be safer than inventing them.
Expansion adds relevant alternative terms to improve recall. A support question containing an internal abbreviation might be expanded with its approved full name and related terminology from a controlled glossary. Decomposition instead separates a question such as “Compare backup retention and restore procedures for production and development” into targeted subqueries. Those searches can run concurrently, with their results merged and deduplicated before context selection. However, adding synonyms indiscriminately can dilute precision, and decomposing a question can lose relationships that require joint reasoning.
In a cloud application, an API handler can first apply inexpensive normalization, then invoke a foundation model only when conversational resolution or complex transformation is needed. Amazon Bedrock can provide model inference for generating query variants. AWS Lambda can implement preprocessing, validate structured rewrite output, and dispatch subqueries. AWS Step Functions can coordinate conditional branches, parallel retrieval, retries, and fallbacks. Treat model-generated queries as untrusted data: validate their structure, constrain their operators, and use parameterized requests rather than concatenating generated text into executable query expressions.
Rewritten queries can feed keyword search, vector search, or hybrid retrieval. Keyword search benefits from exact identifiers and domain terminology, while vector search can benefit from a self-contained description of the information need. A hybrid system may deliberately produce different representations for each path rather than use one expanded string everywhere. In Amazon OpenSearch Service, application and search-pipeline logic can combine lexical and vector results, normalize or fuse scores, and apply supported scoring mechanisms. Raw lexical and vector scores should not be assumed to share a comparable scale.
Query rewriting complements index optimization; it does not replace it. Appropriate text analyzers, metadata mappings, chunk boundaries, embedding choices, and vector-index settings still determine what retrieval can find and how quickly. Similarly, reranking is a separate operation that reorders retrieved candidates rather than transforming the request. Traditional database query rewriting often aims to preserve exact result equivalence; natural-language retrieval rewriting instead aims to preserve information intent and therefore requires empirical relevance testing.
Performance improvements are workload-dependent. A focused rewrite may reduce irrelevant candidates or downstream context size, but model inference and multiple searches can increase end-to-end latency and cost. Bound the number of variants, retrieval depth, execution time, and total context budget. Cache only where identity, tenant, conversation context, and freshness requirements permit, and retain the original query as a fallback when rewriting fails validation or exceeds its deadline.
Evaluate the complete retrieval and answer pipeline against representative labeled questions. Track recall at a chosen retrieval depth, ranking quality, answer correctness, groundedness, tail latency, and cost per request. Preserve exact product codes, negations, date ranges, and jurisdictional requirements. Enforce authorization and tenant filters independently of generated text on every retrieval path; a rewrite must never broaden access. Restrict sensitive query logging and treat instructions embedded in user text as untrusted input to the rewriting model.