Skip to main content
Query Expand stage showing LLM-powered query variations and result fusion
The Query Expand stage uses language models to generate multiple query variations from the original query, executes searches for each variation, and fuses the results. This improves recall by capturing different phrasings and aspects of the user’s intent.
Query expansion explained: an ambiguous two-word query (jaguar speed) is expanded by an LLM into multiple reformulations covering each interpretation, each searches independently, and results fuse via Reciprocal Rank Fusion into one broader ranked list; HyDE instead generates a hypothetical answer document and embeds that paragraph for more signal. Multi-query improves recall for ambiguous queries, HyDE improves precision for short single-intent queries, and both can be combined.

Why expansion works: a short, ambiguous query becomes several reformulations that each search independently and fuse via Reciprocal Rank Fusion; HyDE takes the opposite path and embeds a hypothetical answer instead of the question.

Stage Category: FILTER (Generates and fuses search results)Transformation: 1 query → N query variations → fused results

When to Use

When NOT to Use

Parameters

Fusion Methods

Configuration Examples

How Query Expansion Works

  1. Original Query: “how to fix memory leaks”
  2. LLM Generates Variations:
    • “memory leak detection and resolution”
    • “debugging memory issues in applications”
    • “preventing memory leaks in code”
  3. Execute Searches: Run vector search for each variation
  4. Fuse Results: Combine using RRF or other fusion method
  5. Return: Deduplicated, ranked result set

Reciprocal Rank Fusion (RRF)

RRF combines results from multiple queries using the formula:
Where k is typically 60, and rank_i is the document’s rank in query i’s results.

Output Schema

Each document includes fusion metadata:

Performance

Query expansion adds latency due to LLM generation and multiple searches. Use judiciously for queries where recall improvement justifies the cost.

Common Pipeline Patterns

Expanded Search + Rerank

Expansion + Filter + Summarize

Cost Optimization

Error Handling