Hermes Wiki

Chunking and Map-Reduce Summarization

Concept

Every LLM has a hard token limit, and unlike most resource limits in software, exceeding it doesn't degrade gracefully — the request simply fails. Once an input (a large log dump, a batch of documents, a multi-megabyte diff) exceeds that limit, there's no way to send it in one call; it has to be split into chunks, processed independently, and the results recombined. This is the same map-reduce shape used for distributed batch data processing generally (see DataFlowPatterns/MapReduce-BatchAggregation), applied here to LLM calls instead of data records: map — summarize each chunk independently, in parallel; reduce — summarize the chunk summaries into one final result.

A concrete production version of this: Google Cloud's reference implementation for long-document summarization splits input by fixed character size (64,000 characters per chunk), retrieves each chunk from Cloud Storage via byte-range requests, summarizes all chunks in parallel (map), then concatenates the chunk summaries and makes a single final call to reduce them into one summary. LangChain's MapReduceDocumentsChain generalizes this with an extra step for very large inputs: after mapping, if the resulting chunk summaries still don't fit in one context window, a collapse step recursively regroups and re-summarizes them until they do, before the final combine pass produces the answer.

The chunking step itself has a real design choice buried in it: fixed-size chunking (split every N characters or tokens, regardless of content) is simple and fast but will happily cut a chunk boundary through the middle of a sentence or a logically coherent unit. Semantic chunking — using embeddings or logical structure to find natural boundaries — avoids that, at 3-10x more compute and latency, and can meaningfully improve downstream retrieval/summary precision. The guiding heuristic, as Pinecone's chunking guide puts it: if a chunk of text makes sense to a human without the surrounding context, it will make sense to the language model too — and if it doesn't, neither will the model's summary of it.

Where a model's context window is large enough to fit the whole input directly (e.g. a 1M-token-context model on a modest-sized document), chunking can sometimes be skipped entirely — it's a workaround for a limit, not a technique with independent value once that limit stops binding.

Tradeoffs

Chunking approach Cost/latency Cross-chunk fidelity Complexity
Fixed-size (character/token count) Cheapest, simplest to implement Splits mid-sentence/mid-record; degrades summary and retrieval precision Low
Semantic/logical-boundary chunking 3-10x the compute/latency of fixed-size Preserves locally coherent units, meaningfully better precision Moderate — needs an embedding pass or structural parser
No chunking (large-context model) Single call, no map-reduce overhead at all Best possible — the model sees everything at once Lowest, but only available when the input actually fits

Map-reduce summarization — regardless of chunking strategy — has a ceiling fixed-size and semantic chunking share: information that only makes sense in relation to a different chunk is invisible to a chunk-independent map step. A pattern like "this error occurred on 40 of 1,000 devices" can't be seen by any single chunk's summary if the devices are split across many chunks; the map-reduce pattern does not guarantee any individual detail or cross-section relationship survives to the final result. That's a structural limitation of the pattern, not a chunking-strategy bug — better chunking makes each chunk's own summary more faithful, but doesn't restore cross-chunk visibility.

When to use / when not to

  • Use chunking whenever input size is unbounded, user-controlled, or otherwise could plausibly exceed the model's context window — assume it will happen eventually rather than waiting for a production failure to discover it.
  • Prefer fixed-size chunking for large, relatively uniform inputs (log lines, per-record diffs) where the extra cost of semantic boundary detection isn't likely to change the outcome much.
  • Prefer semantic/logical-boundary chunking when retrieval or summary precision genuinely matters and the input has real internal structure worth preserving (long-form documents, mixed-topic transcripts).
  • Skip chunking entirely once a large-context model comfortably fits the whole input — map-reduce's overhead (extra calls, extra latency, information loss at chunk boundaries) is a cost paid only because a smaller window forced it.
  • Don't reach for map-reduce summarization when the task needs a fact that only makes sense in relation to a different part of the input — the pattern's chunk-independence is exactly what makes it unable to answer that class of question reliably.

Common pitfall

Treating map-reduce summarization as lossless compression instead of what it actually is: independent, chunk-blind summarization followed by a best-effort reduce pass. Because each chunk is summarized with no visibility into any other chunk, any fact or pattern that only becomes meaningful in relation to another chunk — a trend across the whole input, an anomaly that's only notable because of how rare it is elsewhere — is structurally unable to survive the map step. Downstream consumers of the final summary who assume it captured "everything important" will eventually be burned by a real cross-chunk pattern that the pipeline was never capable of seeing.

Engineering Lens

This is the same decomposability assumption classic distributed map-reduce makes about its records — that each unit can be processed independently and the results validly recombined — just applied to text instead of structured data. The failure mode is the same one that shows up whenever that assumption doesn't actually hold for the domain: a distributed aggregation job that assumes independence between records will silently miss cross-record relationships in exactly the same way a chunked LLM summarization pipeline misses cross-chunk patterns. The fix, when it matters enough to be worth the cost, is also the same shape either way: either pre-aggregate the structure programmatically before the per-chunk step (summarize numerically first, send only genuinely ambiguous chunks to the model), or accept that the pipeline answers "what's the gist" and route anything requiring exact cross-record reasoning to a different mechanism entirely.

Sources

Hermes Wiki