Composable Indices and Sub-Question Query
What You'll Learn
You'll learn how to combine multiple specialized indices and break down complex questions into simpler sub-questions for more accurate retrieval.
The Core Problem
Imagine you're asking: "Compare the revenue trends of our US and European divisions over the last three years." This requires pulling information from multiple sources—financial reports from different regions and time periods. A single index might not efficiently handle this multi-faceted query.
Composable Indices: Multiple Sources, One Interface
Composable indices let you combine several indices (vector, keyword, tree, etc.) into a unified structure. Think of it like having multiple filing cabinets—one for US data, one for European data, one for quarterly reports—but querying them all through a single smart assistant.
LlamaIndex allows you to create a top-level index that routes queries to the appropriate sub-indices. Each sub-index specializes in a particular domain, time period, or document collection.
Sub-Question Query Engine: Divide and Conquer
The sub-question query engine automatically decomposes complex queries into simpler sub-questions, sends each to the most relevant index, then synthesizes the answers.
Using our example:
- Sub-question 1: "What are US division revenue trends?" → routed to US financial index
- Sub-question 2: "What are European division revenue trends?" → routed to European financial index
- Synthesize both answers into a comparative response
This approach mirrors how you'd naturally tackle complex research—break it down, gather pieces, then combine insights.
When to Use This Pattern
- Multi-domain queries spanning different knowledge bases
- Questions requiring comparison across categories
- Complex analytical questions that benefit from structured decomposition
- When you have logically distinct document collections
Key Takeaway: Composable indices and sub-question queries let you architect sophisticated retrieval systems that intelligently route and decompose complex questions, significantly improving answer quality for multi-faceted queries.