- Gerenciamento automatizado de sessões
- Direcione para qualquer cidade em 195 países
- Sessões simultâneas ilimitadas
Query Expansion
TLDR: Query expansion adds related terms, synonyms, or reformulations to a search query so that relevant documents using different wording are still retrieved.
Query expansion exists because searchers and documents rarely use identical vocabulary. Someone searching for “laptop battery dying fast” may need a document titled “Reduced battery life in portable computers”. Keyword matching finds no overlap worth scoring. Expansion bridges that gap by searching for more than what was literally typed.
Expansion Methods:
- Synonym expansion: Add known equivalents from a thesaurus or curated list, such as mapping laptop to notebook and portable computer.
- Stemming and lemmatization: Reduce words to a root form so running, ran, and runs all match.
- Spelling correction: Repair likely typos before searching rather than returning nothing.
- Acronym handling: Expand or contract abbreviations in both directions.
- Relevance feedback: Extract frequent terms from top results and re run the search with them added.
- Model generated variants: Use a language model to produce alternative phrasings of the same information need.
Pseudo Relevance Feedback:
The classical automatic method assumes the top results of an initial search are relevant, then uses them to improve the query.
The system runs the original query, takes the highest ranked documents, extracts terms that appear frequently in those documents but rarely in the collection overall, adds those terms with reduced weight, and searches again.
It works well when the first search was reasonably good. It fails badly when it was not, because the method has no way to detect that the top results were wrong. Expanding from irrelevant documents produces a query that is confidently aimed at the wrong target, a failure mode known as query drift.
Model Based Expansion:
EXPAND = """Generate 3 alternative phrasings of this search
query. Vary vocabulary and specificity. Preserve the
underlying information need. Return one per line."""
def expand(query, model, index):
variants = model.generate(EXPAND, query).splitlines()
all_queries = [query] + [v.strip() for v in variants if v.strip()]
seen = {}
for q in all_queries:
for doc in index.search(q, limit=20):
# Keep the best score any variant achieved
if doc.id not in seen or doc.score > seen[doc.id].score:
seen[doc.id] = doc
return sorted(seen.values(), key=lambda d: d.score, reverse=True)
Each variant is searched independently and results are merged, keeping the best score per document. This surfaces documents that only one phrasing would have found, while deduplication prevents the same document appearing repeatedly.
The Recall and Precision Tradeoff:
The pattern below is directional rather than measured. Actual behavior depends heavily on corpus and query type.
| Expansion level | Recall | Precision | Typical outcome |
|---|---|---|---|
| None | Lowest | Highest | Misses differently worded matches |
| Light | Improved | Largely preserved | Usually a net gain |
| Moderate | Higher | Some loss | Depends on use case |
| Aggressive | Highest | Substantial loss | Relevant results buried |
Expansion is not uniformly beneficial. A precise technical query, a product code, or an exact phrase search is usually damaged by it, because the user already supplied the correct term and alternatives only introduce noise.
When to Expand:
The decision is best made per query rather than globally.
Short, vague, or natural language queries benefit most, since the gap between user vocabulary and document vocabulary is widest. Searches returning very few results are good candidates, since recall is the binding constraint. Known synonym rich domains, such as medical or legal terminology, benefit consistently.
Expansion should generally be skipped for quoted phrases, identifiers, code, and queries that already return abundant high quality results. In those cases the user’s wording is the signal, not an obstacle.
Expansion and Semantic Retrieval:
Embedding based retrieval addresses vocabulary mismatch differently, by representing meaning rather than words, so related phrasings land near each other in vector space without explicit expansion.
This does not make expansion obsolete. Embeddings handle synonymy well but can be weak on rare terms, exact identifiers, and domain jargon that was sparse in their training data. The common production arrangement combines both, running expanded keyword search alongside vector search and merging results, which is the approach described in hybrid search.
For systems grounding answers in live web results, expansion also applies at the search engine layer. Issuing several phrasings of a question through Bright Data’s SERP API and merging the results produces broader coverage than any single query returns, which directly improves the material available for LLM grounding.