Sub topic 9
Decomposing complex questions into sub-questions
This chapter assumes you have a working RAG pipeline (index, retrieve, generate). It also assumes you can call an LLM with a prompt and read Python. Earlier chapters covered conversational rewriting, multi-query expansion and reciprocal rank fusion (RRF). Here you add a technique for questions that need several separate pieces of evidence.
The failure this fixes
Multi-query expansion rephrases one question several ways. That helps when the question has one information need and the wording does not match the documents. It does not help when the question contains several information needs.
Consider this question:
> Which is cheaper to run for 10 million requests a month, the Standard plan or the Premium plan, and does either include a free tier?
The question mixes at least three needs: the Standard plan's price, the Premium plan's price, and the free-tier rules. A single embedding of the whole sentence lands somewhere between those topics. The top-k results tend to come from whichever topic dominates the wording. The other facts never reach the prompt, and the model either guesses or says it cannot answer.
Decomposition splits the question into sub-questions. Each sub-question is a focused query with one information need, and each is searched separately.
The working model
Decomposition has four steps:
- Split. Ask an LLM for a short list of self-contained sub-questions.
- Retrieve. Run a normal search for each sub-question.
- Combine. Gather the passages, either as one merged list or grouped by sub-question.
- Answer. Give the generator the original question plus the evidence.
The split step is a prompt. The most important instructions in it are that each sub-question must stand alone, that there is a cap on how many to write, and that a simple question comes back unchanged.
A first implementation
The function below asks for sub-questions, one per line, and falls back to the original question if the model returns nothing usable.
from typing import Callable
def decompose_question(
question: str,
llm: Callable[[str], str],
max_sub: int = 4,
) -> list[str]:
prompt = (
f"Break the question below into at most {max_sub} sub-questions. "
"Each sub-question must be answerable on its own by searching a "
"document collection, and must repeat any names it needs. "
"If the question is already simple, return it unchanged as the "
"only line. One sub-question per line, no numbering.\n\n"
f"{question}"
)
lines = [line.strip() for line in llm(prompt).splitlines() if line.strip()]
return lines[:max_sub] or [question]
def retrieve_per_subquestion(
question: str,
llm: Callable[[str], str],
search: Callable[[str, int], list[str]],
top_k: int = 3,
) -> dict[str, list[str]]:
sub_questions = decompose_question(question, llm)
return {sub: search(sub, top_k) for sub in sub_questions}
if __name__ == "__main__":
docs = {
"standard price": ["Standard costs $0.40 per million requests."],
"premium price": ["Premium costs $0.90 per million requests."],
"free tier": ["Only Standard has a free tier of 1M requests."],
}
def fake_llm(prompt: str) -> str:
return (
"What is the price of the Standard plan per million requests?\n"
"What is the price of the Premium plan per million requests?\n"
"Which plans include a free tier?"
)
def fake_search(query: str, k: int) -> list[str]:
key = "free tier" if "free" in query else (
"premium price" if "Premium" in query else "standard price"
)
return docs[key][:k]
result = retrieve_per_subquestion(
"Which is cheaper at 10M requests, Standard or Premium, "
"and does either have a free tier?",
fake_llm,
fake_search,
)
for sub, passages in result.items():
print(sub, "->", passages)The demo uses stand-ins for the model and the search so that it runs without any service. In a real system you would pass your own llm and search callables.
Returning a dictionary keyed by sub-question matters. The generator prompt can then label each evidence block with the sub-question it answers. That makes it much easier for the model to see which fact supports which part of the answer.
Independent and dependent sub-questions
Not every split is safe to run in parallel. Two kinds of sub-question exist.
| Kind | Example | How to run it |
|---|---|---|
| Independent | "What does Standard cost?" and "What does Premium cost?" | Search all in parallel. |
| Dependent | "Who founded the company that makes Product X?" then "When was that founder born?" | Search in order. The second query needs the first answer. |
The code above handles only independent sub-questions. For a dependent chain, the second sub-question cannot be written in full before the first is answered. A split-first approach produces something like "When was the founder born?", which has no name in it and searches badly. The next chapters cover multi-step retrieval, where earlier results shape later queries. For now, notice the signal: if a sub-question needs a pronoun or a placeholder that only evidence can fill, the question is dependent.
Merging the evidence
You have two reasonable ways to combine results:
- Grouped. Keep each sub-question's passages separate, as in the code above. Use this when the final answer has to cover every sub-question. It guarantees each part gets its own slots in the context.
- Fused. Treat each sub-question's ranking as one list and merge with RRF from the previous chapter. This suits a fixed context budget, since documents relevant to several sub-questions rise to the top.
Grouping is usually the better default for decomposition. RRF rewards agreement between lists, but sub-questions are meant to be different. A passage that answers only sub-question 3 would score low in a fused list, even though the answer needs it. Fusion is more natural for multi-query expansion, where every list is trying to answer the same need.
Choosing between techniques
Pick the technique from the failure you observe.
| Symptom | Likely cause | Technique |
|---|---|---|
| Right document exists but uses different words | Vocabulary mismatch | Multi-query expansion or HyDE |
| Question refers to "it" or "that" | Missing context | Conversational rewriting |
| Question is too specific and misses background | Narrow query | Step-back |
| Answer needs facts from several places | Multi-part question | Decomposition |
You can also combine them. A common pipeline condenses the follow-up first, then decomposes, then runs multi-query expansion on each hard sub-question. Each added stage costs one more model call, so add stages only when evaluation shows a gain.
Common errors
Over-splitting. Models told to "break the question down" will split questions that did not need it. "What is the refund window?" becomes three sub-questions about refunds, windows and policies. The extra searches add noise and cost. Guard against this with the "return it unchanged" instruction, a low cap on max_sub, and a test set of simple questions that must come back as one line.
Sub-questions that cannot stand alone. A sub-question such as "What about its price?" repeats the original problem from the conversational chapter. The prompt must say that each sub-question repeats the names it needs. Check this by reading a sample of outputs.
Lost constraints. The original may say "in 2023" or "for the EU region". If the split drops the constraint from some sub-questions, those searches return the wrong period or region. Add "keep every date, name and constraint that applies" to the prompt.
Unparseable output. The model may number the lines or add a heading such as "Here are the sub-questions:". The simple line-splitting parser would treat the heading as a query. Either strip list markers and skip lines ending in a colon, or ask for JSON and validate it. Whatever you choose, keep the fallback to the original question.
Dropping the original question. Always give the generator the original question, not only the sub-questions. The sub-questions are search tools, and the final answer must still address what the user asked. Some pipelines also search with the original question and add its results as one more group, which protects against a bad split.
Cost and latency
Decomposition adds one LLM call for the split, and N searches instead of one. Run independent searches in parallel (for example with a thread pool or async calls) so that latency grows by the slowest search, not by the sum. The context grows too, since you now pass up to N groups of passages to the generator. Cut top_k per sub-question (2 or 3 is common) to keep the prompt size close to a single-shot search.
Exercise
A user asks, "Does the Pro plan support SSO, and what is its monthly price?" Your system uses decomposition and merges the sub-question rankings with RRF. A passage about SSO ranks first for sub-question 1 and does not appear for sub-question 2. A pricing passage is the reverse. Why might RRF push both passages below a general plan-overview passage that appears at rank 3 in both lists, and what would you change?
Show answer
RRF adds 1/(k+rank) for each list a document appears in. The overview passage appears in both lists, so it collects two scores, while each specific passage collects only one. With k=60, rank 3 in two lists gives 2/63, about 0.0317, and rank 1 in one list gives 1/61, about 0.0164. So the overview passage ranks higher even though neither specific fact is in it. Sub-questions ask for different things, so agreement between lists is not a sign of relevance. Keep the results grouped by sub-question and give each group its own share of the context, or take the top few passages from each list before merging.
Exercise
Write down two checks you would add to a test set to catch over-splitting and constraint loss in a decomposition prompt.
Show answer
For over-splitting, include simple single-fact questions (for example, "What is the refund window?") and assert that the splitter returns exactly one line equal to the question. For constraint loss, include questions with a date or region (for example, "What changed in the EU pricing in 2023, and who approved it?") and assert that every sub-question still contains "EU" and "2023" where they apply.