CLOUD CONCEPT

Query Expansion

Query expansion enriches a search request with related terms or alternative formulations to retrieve relevant information that the original wording might miss.

Cloud Concepts Hub →

What is Query Expansion

Query expansion reduces the vocabulary mismatch between a user's question and the documents that can answer it. In retrieval-augmented generation, it can improve evidence coverage by searching for synonyms, domain terminology, and equivalent questions before selecting context for a foundation model. Its value depends on preserving the user's intent while controlling irrelevant results, latency, and cost.

Query expansion improves retrieval by supplementing an original query with related expressions that may appear in relevant documents. A user might ask about “recovering accidentally deleted files,” while operational documentation describes “object version recovery” or “restoring previous versions.” Searching these related formulations can uncover evidence that a single keyword query misses. Expansion can use curated synonym dictionaries, domain taxonomies, relevance feedback, or a foundation model that generates alternative search expressions.

In retrieval-augmented generation, expansion occurs before or during evidence retrieval, not as a substitute for retrieving evidence. An application can generate several intent-preserving variants, submit the original query and its variants to a search backend, merge the results, remove duplicate chunks, and rerank the candidates. The answer-generating model then receives selected source passages. Generated expansion terms are retrieval aids, not verified facts and not authoritative answer context.

Consider an engineering assistant receiving the question “Why do requests fail when our API gets busy?” An expansion step might produce queries containing “request throttling,” “rate limits,” and “HTTP 429.” These formulations help locate documentation written in technical language. However, overload can also cause timeouts or server errors, so the application should avoid treating one generated interpretation as an established diagnosis. Preserve the original query, generate a bounded set of alternatives, and ask for clarification when ambiguity materially affects the answer.

Expansion is related to, but distinct from, query decomposition and query transformation. Decomposition splits a complex question into independently searchable subquestions, such as separating retention requirements from recovery procedures. Transformation is the broader category of adapting a query, including normalization, rewriting, and translation into a backend-specific format. An effective workflow may decompose a question first and expand each subquestion afterward, but these operations solve different retrieval problems.

In a cloud implementation, an application can invoke a foundation model through Amazon Bedrock to produce structured query variants. AWS Lambda functions can validate the generated output, apply terminology mappings, decompose compound questions, and prepare retrieval requests. AWS Step Functions can coordinate these operations with parallel searches, timeouts, retries, and fallback paths. A search engine such as Amazon OpenSearch Service can execute lexical, vector, or hybrid retrieval. These services provide building blocks; a custom expansion workflow still requires application logic, appropriate model instructions, and evaluation.

Expansion commonly improves recall, but it can reduce precision through query drift: added terms may change the topic or introduce unsupported assumptions. More searches also increase retrieval work, model token consumption, and potentially latency. Limit the number and length of variants, retain exact identifiers and explicit constraints, and consider rank fusion rather than directly comparing raw scores from different retrieval methods. Reranking and deduplication help keep the final context focused, but they cannot guarantee that missing evidence will be recovered.

Security boundaries must remain independent of generated text. Derive tenant and document-access filters from authenticated application context, and apply them consistently to every expanded search. Do not allow model-generated variants to remove authorization constraints or modify trusted filters. Treat user queries and retrieved documents as untrusted inputs, minimize sensitive information sent to models, and protect query logs. Evaluate expansion against an original-query baseline using representative questions, recall at a fixed retrieval depth, ranking quality, grounded answer quality, latency, and cost. Enable it selectively when the measured gains justify the additional complexity.

Key aspects of Query Expansion

Effective query expansion broadens vocabulary coverage while preserving intent, enforcing access controls, and demonstrating measurable retrieval improvements.

Intent-preserving enrichment

Add synonyms, domain terminology, or equivalent formulations without changing the user's objective. Preserve product names, identifiers, dates, and other explicit constraints.

Multiple expansion strategies

Use curated dictionaries for predictable terminology or foundation models for context-sensitive alternatives. Relevance feedback can also suggest terms from initial results, but noisy results can amplify query drift.

Complementary query handling

Use decomposition to separate compound questions and expansion to broaden the vocabulary used for each search. Treat both as distinct steps within a larger query-transformation workflow.

Result fusion and selection

Search with the original query and selected variants, then merge and deduplicate the retrieved passages. Apply rank fusion or reranking to select useful evidence without assuming scores from different searches are directly comparable.

Bounded execution

Cap variant counts, model output length, search concurrency, and execution time. Provide an original-query fallback when expansion fails or exceeds its budget.

Security and measured quality

Apply trusted authorization filters to every retrieval request, regardless of generated query wording. Compare expansion with a baseline using retrieval relevance, grounded answer quality, latency, and cost.

Cloud services for Query Expansion

A custom workflow can use Step Functions to coordinate Lambda-based query validation and decomposition, then invoke a foundation model through Amazon Bedrock to generate bounded query variants. Lambda constructs retrieval requests with trusted access filters, and Amazon OpenSearch Service searches the indexed documents. The workflow merges, deduplicates, and optionally reranks candidates before passing selected evidence to the answer-generating model. Timeouts, limited concurrency, and an original-query fallback control operational risk. Expansion and retrieval quality should be evaluated together rather than assuming that additional searches necessarily improve the answer.

Amazon Bedrock

Applications can invoke foundation models through Amazon Bedrock to generate synonyms, domain-specific expressions, and alternative queries. Model instructions should constrain the output format and preserve user intent; the application must validate the variants before retrieval.

Open Amazon Bedrock →
AWS Lambda image AWS Lambda

Lambda functions can implement terminology mappings, validate generated queries, and decompose complex questions into searchable subquestions. They can also construct search requests with trusted filters and deduplicate returned passages.

Open AWS Lambda →
AWS Step Functions image AWS Step Functions

Step Functions can orchestrate a custom query-handling workflow across model invocation, decomposition, expansion, retrieval, and result processing. Parallel states or Map states, retries, timeouts, and error handling help control execution and provide fallback paths.

Open AWS Step Functions →
Amazon OpenSearch Service image Amazon OpenSearch Service

OpenSearch Service can retrieve documents using lexical, vector, and hybrid search approaches configured for the workload. Applications can submit expanded queries and combine their results, while search analyzers can support configured synonym handling for lexical retrieval.

Open Amazon OpenSearch Service →