Course contentsShow
← AI Engineering
Lesson 370 of 1,88610. RAG - Improving RetrievalFree lesson

Query Expansion with Synonyms

Generating alternative phrasings and synonyms to broaden search coverage and capture semantic variations.

Query Expansion with Synonyms

What you'll learn: How to broaden your RAG search by automatically generating alternative phrasings and synonyms to capture more relevant documents.

The Core Problem

When users search with phrases like "fix a bug," your vector database might miss relevant documents that use "resolve a defect" or "troubleshoot an issue." Even with semantic embeddings, exact phrasing variations can reduce retrieval quality. Query expansion solves this by transforming a single query into multiple semantically equivalent versions before searching.

How It Works

Think of query expansion like casting a wider net. Instead of searching with just the original query, you:

  1. Generate alternatives: Use an LLM or synonym dictionary to create variations of the user's query
  2. Execute multiple searches: Run each expanded query against your vector database
  3. Merge results: Combine and deduplicate the retrieved chunks, often using score fusion techniques you learned earlier

For example, the query "automobile maintenance" expands to:

  • "car maintenance"
  • "vehicle servicing"
  • "automotive care"

Each variation retrieves slightly different documents, increasing the chance you'll find all relevant context.

When to Apply It

Query expansion works best when:

  • Users phrase questions in narrow, specific ways
  • Your knowledge base uses varied terminology
  • Initial retrieval returns too few results
  • Domain-specific jargon has multiple common expressions

It pairs naturally with the hybrid search and score fusion techniques you've already learned, since you're now managing multiple result sets.

Key Takeaway: Query expansion with synonyms broadens search coverage by automatically generating semantically equivalent query variations, helping your RAG system capture relevant documents even when terminology varies across your knowledge base.