Semantic Query Expansion for Web Search in LLM Pipelines
Expanding queries with LLMs helps retrieval but fails on ambiguous and unfamiliar topics.

Semantic query expansion for web search in LLM pipelines is a retrieval engineering discipline. A web search API for AI agents and RAG pipelines must support parallel searches and deliver clean, ranked, token-efficient evidence with freshness appropriate to the question. Reliable pipelines plan expansion, retrieval infrastructure, and security controls together, because broader retrieval helps only when the evidence can support an answer and is safe for the model to use.
Why a single query falls short in LLM pipeline retrieval
An agent can answer confidently while relying on an evidence set too thin to support its conclusion. The failure begins before generation, when its query misses documents that express the relevant concept in different words. Production semantic search relying only on the user’s exact phrasing misses 15-25% of relevant documents. Search need not be broken for retrieval to fail.
Li et al.’s wide-ranging query expansion survey describes vocabulary mismatch as a problem that information retrieval has faced for years. Users say what they want in broad or unclear terms, while documents use domain-specific terms, paraphrases, or new jargon. Agent-generated queries compound the gap because they tend to be short and context-poor. The consequence extends beyond recall to factuality, as missing evidence leaves more room for guessing or hallucination. For time-sensitive questions, weak web retrieval also fails to compensate for the model’s static training knowledge.
What semantic query expansion is and how it addresses vocabulary mismatch
Semantic query expansion transforms a seed query into semantically enriched variants before search runs. Its purpose is to increase the chance that a reformulation matches how relevant documents express the same concept. Intent remains the anchor throughout that transformation. An LLM can produce paraphrases, fuller reformulations, or hypothetical documents.
The Li survey distinguishes this broader design space from classical methods that depend on lexical co-occurrence or static resources, including pseudo-relevance feedback, thesaurus expansion, and log-driven reformulation. LLM-based expansion instead uses context and controllable generation to address under-specified language. Expansion changes the input to retrieval, while reranking changes the order of documents already retrieved. Because expansion comes before retrieval, it shapes which evidence the later stages get to assess.
The three core expansion techniques and what each one is actually doing
Multi-query expansion generates several versions of the original query, searches them in parallel, and merges their results. It widens lexical coverage while preserving the underlying intent. Short or fuzzy queries are its natural fit. Each variant adds a search call and usually an LLM call, so gains in recall come at a higher cost. Reciprocal rank fusion, or RRF, combines the ranked lists by scoring each document once and summing contributions from the lists in which it appears.
Gao et al. (2023) introduced Hypothetical Document Embeddings, or HyDE, which generates a hypothetical answer document from what the user originally asked and retrieves against that document’s embedding. A full answer can resemble relevant documents more closely in embedding space. Its factual details are not themselves evidence. The hypothetical document may contain false details, most of which the dense encoder’s representation filters out during retrieval. HyDE fits short queries against a dense-retrieval corpus, whereas multi-query expansion serves broader lexical coverage across keyword and semantic search.
Query rewriting normalizes phrasing, resolves ambiguity, and fills gaps in an under-specified request. Decomposition instead splits a compound question into focused subquestions whose answers can be combined. These operations can share a pre-retrieval step. Microsoft’s agentic retrieval describes decomposition as breaking compound questions into smaller, focused subqueries, supporting tasks in which one retrieved fact enables the next query. Structured extraction complements this work by mapping constraints such as job title, location, and date into attribute-value pairs for filtering and ranking.
How expansion fits into and changes the broader RAG and agent retrieval loop
A standard RAG pipeline embeds a query, matches it against a vectorized document collection, and places retrieved chunks into the generation prompt. Expansion intervenes before embedding and matching, but its role changes with the surrounding architecture. Search-first pipelines always retrieve before generating. Tool-use pipelines let the LLM decide when to search, while agentic loops repeat retrieval and reasoning across multiple rounds. In those loops, an early expansion shapes the evidence available for later queries, so a poor decision can propagate.
Parallel searches produce overlapping results that must be fused before reranking. A search layer that returns deduplicated, ranked results gives the application less work to do, though it still has to handle overlap between separate searches. The reranker needs a clean candidate set with a range of results. Model preparation then packages the selected evidence into structured, token-efficient content, because redundant HTML consumes context without adding useful support. Expansion quality thus depends on how well fusion, reranking, and generation work with it.
Where LLM-based expansion breaks down and what the research shows
Abe et al.’s 2025 study, LLM-based Query Expansion Fails for Unfamiliar and Ambiguous Queries, found that expansion can significantly degrade retrieval when model knowledge is insufficient or query ambiguity is high. The model can produce incorrect expansions when it lacks the knowledge it needs, while biased refinements can miss some readings of an unclear request. Ambiguity is therefore not an automatic reason to expand. Short, fuzzy, or linguistically diverse queries can gain recall, but precise numerical and domain-specific queries may show limited or negative returns.
Query drift is the central structural failure. A generated variant can remain topically related while moving away from the user’s actual question. A single expansion model adds another constraint because its variants tend to cluster within its own knowledge distribution rather than represent genuinely different perspectives. Generating more variants may still leave them in that cluster. It does, however, multiply search and embedding calls, creating latency and cost pressure without batching and a hard limit.
The strongest objection goes beyond inefficient retrieval. More documents do not guarantee better reasoning when the search layer returns noisy, low-quality, or adversarial content. Expansion can amplify those defects. An injected instruction in retrieved material also turns a relevance problem into a security problem.
Research-backed approaches to making expansion more reliable at scale
Choi et al. (2026) propose building in-domain exemplars automatically to replace hand-crafted prompts and demonstrations chosen by hand. Their framework uses a BM25–MonoT5 pipeline to build exemplar pools from the target corpus, then uses cluster-based selection to show the LLM a range of domain vocabulary. This targets domain shift without requiring human annotation or fine-tuning. The approach is label-free and training-free by design.
Multi-LLM ensembling addresses the narrower perspective of a single model. Two heterogeneous LLMs independently generate expansions, and a third refinement LLM consolidates their outputs into one coherent expansion. Diversity alone is not the complete solution. Refinement removes contradictory or redundant terms that could otherwise damage retrieval. The framework reports consistent, statistically significant gains across TREC DL20, DBPedia, and SciFact over BM25, Rocchio, zero-shot, and fixed few-shot baselines.
Adaptive gating tackles a different failure, expanding a query that needs no expansion. A gate decides whether and how to augment a query based on its content and context. This makes restraint part of retrieval engineering. Precise queries that already match the language in the corpus can skip generation, which saves needless cost and leaves less room for drift.
What should a web search API for AI agents and RAG pipelines provide?
A search API designed for RAG must return usable evidence. Traditional SERP wrappers return titles, URLs, and snippets, leaving the application to open links, scrape pages, clean content, and select material for the model. Expansion multiplies that unfinished work across query variants. An AI-native API instead bundles content extraction into a single call, returns Markdown or JSON rather than raw HTML, and applies context-aware filtering.
Scraping introduces noise, staleness, and inconsistent structure into that delivery path. Layout changes can break parsing, crawl schedules can leave content hours or days behind, and different runs can produce incompatible schemas. More queries expose more of this fragility. Pre-ranked, deduplicated, token-efficient output reduces the preprocessing burden within each call, while predictable latency supports parallel execution. Neither clean formatting nor semantic relevance, however, establishes that the underlying information is current.
Freshness is therefore a separate selection criterion. Vector stores can become stale even while the underlying web changes, so time-sensitive questions require live web grounding. Prices, current events, and rapidly changing facts make this requirement concrete. For these workloads, the best fit depends on evidence quality, extraction, ranking, parallel-call reliability, and freshness together. A strong expansion method cannot compensate for an API that bottlenecks those capabilities.
Security and trust boundaries that expansion opens in production pipelines
Aim Security disclosed EchoLeak in June 2025, documenting a zero-click prompt injection exploit against Microsoft 365 Copilot. EchoLeak, CVE-2025-32711 with CVSS 9.3, used a single crafted email to cause access to internal files and transmission of their contents to an attacker-controlled server. No user interaction was required for the exploit. The inbox was the entry point, and retrieval brought the malicious content into the system’s working context. The case demonstrates why retrieved text cannot be treated as instructions.
Expansion enlarges this exposure by admitting more documents into the retrieval path. Each additional source is a potential injection vector, even when it appears relevant to the query. A system prompt is not an access control. Telling the model to answer only authorized users does not protect sensitive text that has already entered its context. Trust boundaries require access controls, metadata filtering, and content provenance checks at the retrieval layer, before content reaches generation.
Infrastructure must enforce those boundaries across deployment environments. Hybrid designs that keep sensitive data on-premises and less critical data in an isolated cloud network require retrieval to respect data residency and access governance. Expansion strategy cannot be finalized independently of those constraints. The sources a variant can reach and its wording determine the exposure it creates.
Production tradeoffs engineers must resolve when deploying query expansion
The practical starting range is three to five variants, with diminishing recall gains beyond that range competing against growth in search and embedding costs. More is not a default improvement here. To keep that growth in check, teams should limit the number of variants and batch embedding calls before deployment. Adaptive gating should skip expansion for precise numerical queries, very specific technical lookups, and requests that already use the language of the corpus.
Technique selection should follow the retrieval architecture described earlier rather than apply multi-query expansion and HyDE unconditionally. The same discipline applies after retrieval. RRF with k=60 is an established fusion baseline, and hash-based or similarity-threshold deduplication keeps documents that are almost the same from appearing again in the candidate set. Hybrid retrieval with neural reranking consistently outperforms multi-query-only setups on recall benchmarks. That comparison gives teams a reason to improve how they select results after retrieval before adding more expanded searches.
Operational validation must also reflect parallel load. A search layer needs predictable latency across concurrent expansion calls. For time-sensitive workloads, live grounding remains a requirement even when cached retrieval is cheaper or easier. Access controls, filtering, and provenance checks must be settled before variant counts and source coverage are finalized. Expansion algorithms and retrieval infrastructure are one design problem, and deploying them as separate concerns leaves the pipeline’s weakest stage in control of the result.


