What query expansion is
Users and documents describe the same thing in different words. A query for cancel subscription misses a help page titled Ending your plan. Semantic search closes some of that gap with meaning-based matching, but keyword search cannot, and neither handles a long question that is really three questions.
Query expansion works on the query side. Before searching, it produces more or better queries from the one the user typed, runs them, and merges the results.
Techniques
| Technique | What it does | Example |
|---|---|---|
| Synonyms | Adds equivalent terms | cancel → cancel, end, terminate |
| Rewriting | Turns a conversational question into a search query | so how do I get my money back? → refund policy |
| Sub-queries | Splits a compound question into parts | pricing and limits for the API → two queries |
| Multi-query | Several phrasings of the same question | Three paraphrases, searched separately |
| Keyword and phrase extraction | Pulls out exact terms and names to match literally | An error code or product name |
Classic expansion used thesauri and pseudo-relevance feedback: search once, take frequent terms from the top results, search again. Current systems more often ask a language model to do the rewriting, because it handles conversational input and can split a question into parts.
Running several queries
Once one query has become several, each runs against the index and returns its own ranked list. Those lists have to be merged. Reciprocal rank fusion is the usual method: a document that ranks well for several sub-queries collects credit from each and rises.
The example shows the shape, not any particular product: one rambling question becomes three focused searches and a few literal terms.
When expansion hurts
- Drift. Each added term is a chance to pull in off-topic results. Apple expanded with fruit ruins a search about the company.
- Expanding precise queries. An error code, version number or quoted phrase should be searched exactly. Expansion helps vague queries and hurts exact ones.
- Ignoring the corpus. Synonyms the documents never use add cost and nothing else. Expansion works best when it favours the corpus's own vocabulary.
- Latency and cost. An LLM rewrite adds a model call before every search. Cache it, and skip it for short queries that do not need it.
- No fallback. If the rewriting step fails, search the original query rather than failing the request.
How SarvCrawl handles it
Query rewriting in SarvCrawl happens in knowledge-base smart search, POST /api/kb/:id/search/smart. Long or multi-line input goes to an LLM planner that rewrites it into up to five sub-queries plus keywords, exact phrases and entities, biased toward the knowledge base's own vocabulary, with a rule-based fallback if the planner is unavailable. Each sub-query runs vector search and BM25, and everything is fused with RRF. Results are cached for five minutes.
Other searches use the query as given. Keyword and hybrid knowledge-base search do no rewriting, and web search does no query expansion: the query you send is the query searched. Knowledge-base search is on paid plans; see the KB search docs.
Frequently asked questions
Is query expansion still useful with vector search?
Yes, for different reasons. Vector search already handles synonyms reasonably well, but it embeds a long compound question as one vector. Splitting it into sub-queries lets each part find its own passages.
What is multi-query retrieval?
Generating several phrasings or sub-questions from one query, searching each separately, and fusing the result lists, usually with reciprocal rank fusion.
When should I not expand a query?
When it is already precise: an identifier, an error message, a version number or a quoted phrase. Expansion adds alternatives, and for exact lookups alternatives are noise.
What is the difference between query expansion and query rewriting?
Expansion adds terms or queries alongside the original; rewriting replaces it with a better search query. Many systems do both, rewriting a conversational question and then splitting it into parts.