When to Use
Complex questions that span multiple topics or require information from different documents. A single retrieval cannot find all the pieces.
Example: “How does our refund policy compare to our competitor’s, and what are the legal implications?”
This needs information from: (1) our refund policy, (2) competitor’s refund policy, (3) legal requirements. No single chunk contains all three.
How It Works
The LLM breaks the question into sub-questions. Each sub-question is retrieved independently. The results are combined and the LLM synthesizes a final answer from all retrieved chunks.
# Sub-question decomposition
decompose_prompt = ChatPromptTemplate.from_template(
"""Break this complex question into 2-4
simpler sub-questions that can each be
answered independently:
Question: {question}
Sub-questions:"""
)
# Input: "How does our refund policy compare
# to competitors, and what are the
# legal implications?"
# Output:
# 1. What is our current refund policy?
# 2. What are our competitors' refund policies?
# 3. What are the legal requirements for
# refund policies in our jurisdiction?
# Each sub-question → separate retrieval
# All results → combined context → final answer
LlamaIndex’s SubQuestionQueryEngine implements this pattern natively. It decomposes the question, routes each sub-question to the appropriate index (if you have multiple), retrieves independently, and synthesizes a final answer. LangChain offers similar functionality via custom chains.