Query expansion
Rewriting a user’s search into several fuller queries, with synonyms and related terms, before searching, so short or vague questions still find matches.
Query expansion rewrites a user’s search into several fuller queries, with synonyms and related terms, before searching, so short or vague questions still find matches. It works on the question side of search, while chunking and embeddings work on the document side.
Users type two words; documents use other words. A model rewrites the query into variants (or into a hypothetical answer to search with, a method published as HyDE in 2022), each variant is searched, and the results are merged, often with the same rank fusion used in hybrid search. It raises recall noticeably for vague questions, at the cost of an extra model call and some latency. Negative terms, things the user does not want, can be extracted the same way and used as filters.
Expansion can also drift: a variant with the wrong synonym pulls in irrelevant results, so check precision as well as recall after adding it. In agentic RAG the model does this on the fly, rewriting the query after it sees poor results instead of expanding once up front.
Sources
Related terms
- Hybrid search: Combining keyword search (such as BM25) with vector search, so results match both exact terms and meaning.
- RAG (retrieval-augmented generation): Finding relevant documents first and putting them into the prompt, so the model answers from them.
- Vector database (pgvector and others): A database that stores embeddings and finds the nearest ones to a query vector quickly, which is the search step behind most RAG systems.
- Agentic RAG: RAG where the model decides what to search for, reads the results and searches again if needed, instead of one fixed retrieval step.
- Recall (AI metric): The share of all correct items that the system actually found: of everything it should have caught, how much it did.
- Precision (AI metric): The share of returned results that are actually correct: of everything the system flagged or retrieved, how much was right.
