Match LlamaIndex Response Synthesizers to use cases
Four synthesizers, four shapes: compact (one call), refine (sequential improve), tree_summarize (recursive merge), accumulate (one answer per node).
Think of writing a report from a stack of notes. Compact: skim the stack at once and write the report in one sitting. Refine: read one note, write a draft, read the next note, improve the draft, repeat. Tree-summarize: split the stack into piles, write a mini-summary per pile, then summarize the summaries. Accumulate: write a separate paragraph about each note and staple them together. Same stack, four very different writing styles. And the right pick depends on how big the stack is and what shape of report you need.
Detailed answer & concept explanation~4 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
6 min: four synthesizers, call shapes, when each wins, production guard against silent truncation, when to write a custom synthesiser.
from llama_index.core import VectorStoreIndex, get_response_synthesizer
from llama_index.core.response_synthesizers import ResponseMode
index = VectorStoreIndex.from_documents(docs)
# Compact: cheap default, single LLM call
compact_qe = index.as_query_engine(response_mode=ResponseMode.COMPACT)
# Tree summarize: hierarchical merge for long-context summarisation
tree_qe = index.as_query_engine(response_mode=ResponseMode.TREE_SUMMARIZE)
# Accumulate: per-node answers concatenated
acc_qe = index.as_query_engine(response_mode=ResponseMode.ACCUMULATE)
# Refine: sequential improvement across nodes
refine_qe = index.as_query_engine(response_mode=ResponseMode.REFINE)
| Synthesizer | LLM calls | Aggregation shape | Best fit |
|---|---|---|---|
| compact | 1 | Stuff and answer | Short-context QA, cheap default |
| refine | N (sequential) | Incremental improvement | Ordered nodes, each adds a refinement |
| tree_summarize | O(log N) depth | Hierarchical merge | Long-document summarisation that overflows window |
| accumulate | N (parallelisable) | Independent per-node answers | Per-source citation, comparative review |
Real products, models, and research that use this idea.
- Notion AI's enterprise document search uses compact plus rerank for most QA and tree_summarize for executive summaries across multi-document corpora
- Legal-tech tools like Harvey use accumulate when each cited authority must produce its own grounded paragraph in the response
- Long-PDF summarisation features (e.g. Mendeley, Scite) lean on tree_summarize because individual papers overflow any single prompt window
What an interviewer would ask next. Try answering before peeking at the approach.
QWhen would you write a custom ResponseSynthesizer rather than pick one of the four?
QHow does tree_summarize parallelise across the tree?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Defaulting to compact for every query. The cheap default fails the moment retrieval exceeds the context window, and silently truncates context for the harder questions where context matters most.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.