query expansion
Query expansion is a technique that reformulates or enriches a search query with extra terms before retrieval, so a system finds relevant documents even when the original wording misses them. A long-standing idea in information retrieval, it is now central to retrieval-augmented generation (RAG), where the retrieved context sets a ceiling on how good the model’s answer can be.
Expansion sits at the front of the retrieval pipeline that produces that context:
Classic approaches add synonyms, stem words to their root forms, correct spelling, or reweight terms to sharpen the match. Pseudo-relevance feedback goes further, expanding a query with terms drawn from the top results of a first search pass.
In modern pipelines, a large language model often does the expanding. Multi-query generation rewrites one question into several phrasings, while HyDE, or hypothetical document embeddings, drafts a hypothetical answer and embeds that instead of the raw query to search a vector database.
The core trade-off is recall versus precision. Broadening a query surfaces more candidate documents but can also pull in noise, so retrieval systems often pair expansion with re-ranking to keep the strongest matches on top.
Related Resources
Tutorial
LlamaIndex in Python: A RAG Guide With Examples
Learn how to set up LlamaIndex, choose an LLM, load your data, build and persist an index, and run queries to get grounded, reliable answers with examples.
For additional information on related topics, take a look at the following resources:
- Using LlamaIndex for RAG in Python (Course)
- Build an LLM RAG Chatbot With LangChain (Tutorial)
- Embeddings and Vector Databases With ChromaDB (Tutorial)
- Vector Databases and Embeddings With ChromaDB (Course)
- Natural Language Processing With Python's NLTK Package (Tutorial)
- Prompt Engineering: A Practical Example (Tutorial)
- LlamaIndex in Python: A RAG Guide With Examples (Quiz)
- First Steps With LangChain (Course)
- Build an LLM RAG Chatbot With LangChain (Quiz)
- Embeddings and Vector Databases With ChromaDB (Quiz)
- Natural Language Processing With Python's NLTK Package (Quiz)
- Practical Prompt Engineering (Quiz)
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Martin Breuss • Updated Sept. 25, 2026