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

Query Decomposition for Complex Questions

Breaking complex queries into simpler sub-queries that can be answered independently and merged.

Query Decomposition for Complex Questions

What you'll learn: How to break down multi-part user questions into simpler sub-queries that your RAG system can answer independently before combining the results.

The Problem with Complex Questions

When users ask complex questions like "Compare the pricing of product A and B, and explain which has better customer reviews," a single vector search often struggles. The embedding may dilute across multiple concepts, returning mediocre results for everything instead of excellent results for each part.

How Query Decomposition Works

Think of it like a project manager breaking down a big task into smaller, manageable pieces:

  1. Analyze the user's question to identify distinct sub-questions
  2. Generate simpler, focused queries (e.g., "What is product A's pricing?" and "What are product B's customer reviews?")
  3. Execute each sub-query independently against your vector database
  4. Synthesize the retrieved contexts into a comprehensive answer

Why This Improves Retrieval

Each decomposed query can be embedded and searched with laser focus. "Product A pricing" retrieves pricing documentation clearly. "Product B reviews" finds review-specific content. You get higher-quality, more relevant chunks for each concept rather than mixed results.

Implementation Pattern

You typically use an LLM to decompose queries before retrieval:

  • Prompt the LLM to identify sub-questions
  • Run separate retrievals for each
  • Pass all contexts to the final generation step with instructions to synthesize

This works especially well for comparison questions, multi-hop reasoning ("What did the CEO of company X say about topic Y?"), and questions requiring information from different document types.

Key Takeaway: Query decomposition transforms one difficult retrieval problem into several easy ones, letting you gather precise context for each aspect of a complex question before generating a comprehensive answer.