New1 billion tokens free on sign-up — crawl, parse, chunk and embed on the houseSee pricing
SarvCrawlSarvCrawl

Glossary · Search and retrievalUpdated

What is query expansion?

Query expansion is the practice of rewriting or adding to a user's search query before retrieval, with synonyms, related terms, rephrasings or several sub-queries, so the search finds relevant documents that do not share the query's exact words.

01What query expansion isof 06

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

TechniqueWhat it doesExample
SynonymsAdds equivalent termscancel → cancel, end, terminate
RewritingTurns a conversational question into a search queryso how do I get my money back? → refund policy
Sub-queriesSplits a compound question into partspricing and limits for the API → two queries
Multi-querySeveral phrasings of the same questionThree paraphrases, searched separately
Keyword and phrase extractionPulls out exact terms and names to match literallyAn 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.

{
  "input": "We moved to the new SDK and now crawls time out and the bill went up. What changed?",
  "sub_queries": [
    "SDK migration breaking changes",
    "crawl timeout",
    "billing changes"
  ],
  "keywords": ["SDK", "timeout", "billing"]
}

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.

SarvCrawl

Turn any site into a searchable knowledge base

Crawl pages and parse documents into clean markdown, then chunk, embed and search them from one API.