Course contentsShow
← Machine Learning and Deep Learning
Lesson 2015 of 3,53843. Retrieval-Augmented Generation: Advanced TechniquesFree lesson

Query Expansion with Synonyms and Related Terms

Augmenting queries with semantically related words to broaden retrieval coverage without losing intent.

Query Expansion with Synonyms and Related Terms

You'll learn how to broaden retrieval coverage by enriching user queries with semantically similar words while preserving the original search intent.

The Core Problem

When users search with specific terms like "car malfunction," relevant documents might use "vehicle breakdown," "automobile failure," or "engine problem." Pure vector or keyword search might miss these variations, limiting recall.

What Is Query Expansion?

Query expansion augments the original query with synonyms, related terms, and semantic variants before retrieval. Instead of searching for just "car malfunction," you search for "car OR vehicle OR automobile malfunction OR breakdown OR failure."

This technique acts like casting a wider net: you catch more potentially relevant documents without drifting into unrelated territory.

How It Works in RAG

Before embedding or searching, you:

  1. Identify key terms in the user's query
  2. Generate expansions using synonym databases (WordNet), LLMs, or domain-specific thesauri
  3. Append or interleave these terms into the query
  4. Retrieve with the expanded version

For example:

  • Original: "python memory leak"
  • Expanded: "python OR py memory OR RAM leak OR overflow OR excessive usage"

The LLM can generate contextually appropriate expansions: "Show me synonyms for 'memory leak' in programming contexts."

When to Use It

  • Domain-specific jargon where multiple terms mean the same thing
  • Sparse documents where exact keyword matches are rare
  • Complementing vector search, especially in hybrid retrieval where BM25 benefits from expanded keywords

Key Takeaway: Query expansion trades precision for recall by adding semantically related terms, helping RAG systems retrieve more relevant documents that use different vocabulary than the user's original query.