
- MapReduce handles large documents by processing smaller chunks independently and combining their outputs into one final summary.
- In our PoC, a 120-page movie script produced 245 chunks and required 246 LLM calls.
- The Map stage accounted for more than 98% of the total runtime, making concurrency the clearest opportunity for improvement.
- The complete run cost $0.073 based on the model pricing used during the test.
- MapReduce improves processing coverage and cost predictability, but it does not guarantee that every detail or cross-section relationship will survive summarization.
- It works best when broad document coverage matters more than deep reasoning between distant sections.
LLMs can summarize short documents effectively, but long inputs introduce a different set of problems. A movie script, policy manual, research paper, or book may fit within a model’s available context window and still produce uneven coverage, slower responses, and higher processing costs.
To test a more controlled approach, we built a MapReduce proof of concept using LangChain and GPT-4o-mini and ran it on a 120-page movie script. We wanted to answer three practical questions: Could the complete document be processed systematically? Where would latency accumulate? And could the cost remain predictable as the document grew?
This article explains the architecture, implementation, benchmark results, and limitations we observed during the PoC.
The Long-Context Problem in LLMs
A larger context window determines how much text a model can accept, but it does not automatically guarantee consistent reasoning across that text. As document length grows, requests generally become slower and more expensive, while important details may receive uneven attention.
A single long prompt can also be difficult to operate reliably. One failed request may require the entire document to be processed again, and it becomes harder to identify which section caused an incomplete or inaccurate result.
This leads to a more useful engineering question: rather than asking how much text can fit into one request, how can the workload be divided, measured, retried, and combined safely?
What Is MapReduce in LLM Systems?
MapReduce is a processing pattern in which a large task is divided into smaller independent operations, and their outputs are later combined.
For LLM-based document summarization, the workflow has two stages:
Map: Split the document into bounded chunks and ask the model to extract or summarize the required information from each one.
Reduce: Combine the intermediate outputs, remove repetition, and generate a document-level result.
This changes the problem from asking one model to understand everything at once to processing local sections first and aggregating them afterward.
In practice, this approach can:
- Keep individual model calls within configured input limits.
- Process every configured chunk systematically.
- Make token usage and model-call counts easier to estimate.
- Allow independent Map calls to run concurrently.
- Isolate failures so individual chunks can be retried.
The tradeoff is that relationships between distant sections may be weakened when the original text is compressed into intermediate summaries.
Map Reduce Architecture for Long Documents
At a system level, the architecture separates document processing into two controlled stages: a parallel Map phase and a consolidated Reduce phase.

During the Map phase, the document is split into size-bounded chunks. Each chunk is processed independently using the same prompt template. These calls are stateless, meaning they do not rely on shared memory or prior outputs. This makes the phase highly parallelizable and easy to scale horizontally.
The intermediate outputs are then passed to the Reduce phase, where they are aggregated into a final structured summary. Because the Reduce step operates on compressed representations rather than the complete raw document, it was considerably faster and less expensive than the Map stage in this PoC.
Key Architectural Properties
Independent Map calls: A failed chunk can be retried without restarting the complete document.
Parallelizable workload: Multiple chunks can be processed concurrently when API and infrastructure limits allow it.
Controlled aggregation: The Reduce stage receives smaller intermediate outputs instead of the complete document.
Stage-level observability: Tokens, latency, errors, and cost can be measured separately for Map and Reduce.
Traceable outputs: Intermediate results can retain page or chunk references for verification.
Workflow Used in the PoC
The PoC followed a fixed workflow:
- Upload the document: A PDF is uploaded through the Gradio interface.
- Extract the content: Text is parsed from each page and converted into a processable document format.
- Create bounded chunks: The extracted text is divided into smaller segments with controlled overlap.
- Run the Map stage: Each chunk is processed using the same summarization prompt.
- Store intermediate outputs: The chunk-level summaries are retained for aggregation and inspection.
- Prepare the Reduce input: Intermediate summaries are combined into a single structured input.
- Run the Reduce stage: The model generates the final document-level summary.
- Report metrics: The application displays token usage, execution time, model-call count, and estimated cost.
This design made it possible to identify which stage consumed the most time and tokens instead of treating the workflow as one opaque request.

Minimal Coding Walkthrough
1. Chunking
splitter = RecursiveCharacterTextSplitter(
chunk_size=1200,
chunk_overlap=200,
)
chunks = splitter.split_documents(documents)Chunking keeps each model request within a controlled input size. The overlap carries a limited amount of neighbouring text into the next chunk, reducing the chance that a sentence or idea is separated at the boundary.
Walk away with actionable insights on AI adoption.
Limited seats available!
Note on units: with the default splitter configuration, chunk size may be measured in characters rather than model tokens. A production implementation that requires token-bounded chunks should use a tokenizer-aware length function and document the model tokenizer used.
2. Map Phase
for chunk in chunks:
response = llm.invoke(map_prompt.format(text=chunk.page_content))
map_summaries.append(response.content)- Creates one model call for each chunk.
- Produces the intermediate outputs used by the Reduce stage.
- Accounts for most of the runtime and model usage.
- Runs sequentially in this minimal example.
- Can be converted to bounded concurrent execution in a production workflow.
3. Reduce Phase
final_summary = llm.invoke(
reduce_prompt.format(text="\n\n".join(map_summaries))
).contentThe Reduce request combines the chunk-level outputs into a single document-level summary. It is smaller than a request containing the complete raw document, but its size still grows as the number or length of intermediate summaries increases.
For much larger collections, a single Reduce request may itself become too large. In that case, the summaries can be reduced in multiple levels rather than combined all at once.
Performance Results from the PoC
The PoC was evaluated on a 120-page movie script to measure document scale, latency, token usage, and estimated model cost.
| Metric | Result |
Document length | 120 pages |
Chunks created | 245 |
Map calls | 245 |
Reduce calls | 1 |
Total model calls | 246 |
Total execution time | 1,645 seconds |
Map-stage time | 1,614 seconds |
Reduce-stage time | 30 seconds |
Average Map latency | 6.6 seconds |
Prompt tokens | 179,772 |
Completion tokens | 77,136 |
Estimated total cost | $0.073 |
These numbers describe one PoC run and should not be treated as a general benchmark for every model or document. Document structure, prompt length, output limits, retries, concurrency, and model response time can materially change the result.
What the Results Tell Us
1. The Map stage dominated the runtime
The Map stage consumed approximately 98.1% of the recorded runtime. In this PoC, that made the Map execution strategy the clearest optimization target.
Reducing the final prompt would have had relatively little effect compared with introducing safe concurrency, shortening Map outputs, or improving request handling.
2. Model-call growth was easy to estimate
In this implementation, every additional chunk created one additional Map request.
The number of model calls therefore grew directly with the number of chunks, although total token usage and latency also depended on chunk length, output length, retries, and concurrency settings.
3. The model cost remained low for this test
Using the model pricing applied at the time of testing, the complete run cost approximately $0.073.
The result shows that this particular document could be processed at a low model cost, although production expenses would also include extraction, storage, monitoring, retries, and infrastructure.
What Map Reduce Preserves and What It Does Not
MapReduce preserves processing coverage, but that should not be confused with perfect document understanding.
Every configured chunk is sent through the Map stage, and every successful intermediate output can be passed into Reduce. However, information may still be lost when raw text is compressed into a chunk-level summary. Relationships between distant sections may also be missed if neither Map output explicitly captures them.
The approach is therefore well suited to:
- High-level summarization.
- Theme and topic extraction.
- Initial policy or compliance review.
- Report and research-paper overviews.
- Workflows where each chunk produces structured fields.
- It requires additional safeguards when the task depends on:
- Comparing exact clauses from distant pages.
- Tracking an entity throughout a long narrative.
- Preserving precise quotations or numbers.
- Reconstructing cause-and-effect relationships across sections.
For those cases, MapReduce can be combined with source references, structured extraction, retrieval, or a verification pass over the original text.
Limitations of MapReduce
1. Relationships between distant chunks may be missed
Map calls do not automatically know what appeared in earlier or later chunks. The Reduce stage can only work with information retained in the intermediate outputs.
2. Compression can remove important details
A weak or overly general Map summary may discard a detail before the Reduce stage sees it. Structured prompts, source references, and task-specific fields can reduce this risk.
3. The Map stage can become slow
One request is required for every chunk. Sequential execution therefore becomes expensive in time as the document grows. Concurrency can help, but it must account for rate limits, failures, and resource usage.
4. The Reduce input can also grow too large
Hundreds or thousands of detailed Map outputs may exceed the final model’s practical input size. Larger workflows may require hierarchical reduction, clustering, or multiple aggregation passes.
5. Overlapping chunks introduce duplication
Overlap helps preserve boundary context, but repeated text can appear in multiple Map summaries. The Reduce prompt must identify and merge duplicate information.
6. Evaluation is still required
Processing every chunk does not prove that the final result is accurate. The workflow needs an evaluation method based on factual consistency, coverage, omission rate, or task-specific quality criteria.
Walk away with actionable insights on AI adoption.
Limited seats available!
Map Reduce vs Refine
MapReduce and Refine are both used for long-document summarization, but they make different tradeoffs.
| Aspect | MapReduce | Refine |
Execution | Independent Map calls followed by aggregation | Each step depends on the previous output |
Concurrency | Map calls can run concurrently | Usually sequential |
Latency | Can be reduced through bounded concurrency | Generally increases with every additional chunk |
Cost estimation | Easier to estimate from chunk and output counts | May grow as accumulated context is repeatedly passed forward |
Cross-section continuity | Weaker unless Map outputs capture shared context | Stronger because earlier information is carried forward |
Failure recovery | Individual Map calls can be retried | A failed step may interrupt the sequential chain |
Best suited for | Coverage, throughput, and operational control | Tasks that depend on progressive narrative continuity |
In the same PoC environment, our Refine run took several hours, while the MapReduce run completed in 1,645 seconds. This is an implementation-specific observation rather than a universal benchmark.
Differences in models, prompts, output lengths, retry behaviour, and execution settings can significantly affect the result, so this should be treated as a PoC observation rather than a universal benchmark.
Practical Improvements for Production Use
The basic pattern is simple, but production systems need more than chunking and two prompts. The following improvements make the workflow more reliable:
Use structured Map outputs. Ask for defined fields such as entities, decisions, dates, risks, or claims instead of a free-form summary alone.
Keep source references. Store page numbers or chunk identifiers with each intermediate output so the final result can be checked against the original document.
Add bounded concurrency. Run several Map requests at once without exceeding model rate limits or creating unmanageable retry traffic.
Make retries idempotent. A failed chunk should be safely reprocessed without duplicating stored outputs.
Use hierarchical reduction. Reduce groups of summaries first when a single final aggregation would exceed a practical input limit.
Evaluate summary quality. Track omission, factual consistency, citation accuracy, and task-specific completeness instead of relying on latency and cost alone.
Separate models by stage. A smaller model may be sufficient for structured extraction in Map, while a stronger model handles the final synthesis.
Frequently Asked Questions (FAQ)
What is MapReduce in LLM document summarization?
MapReduce is a workflow in which a long document is divided into smaller chunks, each chunk is processed independently, and the resulting outputs are combined into a final summary or analysis.
Does MapReduce preserve every detail in a long document?
No. It ensures that every configured chunk can be processed, but details may be lost when each chunk is compressed. Important facts should be captured through structured Map prompts, source references, or a separate verification step.
When is MapReduce better than sending the complete document in one prompt?
It is useful when the document is too large or expensive to process reliably in one request, when individual sections must be retried independently, or when predictable call counts and stage-level monitoring are important.
How can MapReduce latency be reduced?
The largest improvement usually comes from running independent Map calls with bounded concurrency. Other options include reducing chunk count, shortening intermediate outputs, batching compatible requests, and selecting a faster model for the Map stage.
What happens when the combined Map summaries are too large?
The workflow can use hierarchical reduction. Smaller groups of summaries are reduced first, and those outputs are then combined in one or more additional aggregation stages.
When should MapReduce not be the first choice?
It may not be suitable for short documents or tasks that depend heavily on precise relationships between distant sections. Refined retrieval-based workflows or direct long-context prompting may provide better continuity in those cases.
Conclusion
The PoC showed that context-window size was only one part of the long-document problem. The more practical challenge was controlling how the document was divided, what information was retained, where latency accumulated, and how failures could be traced.
MapReduce made those tradeoffs easier to observe. It processed the document in bounded sections, isolated the most expensive stage, and kept the final aggregation smaller than the complete source text. However, it did not guarantee that every detail or cross-section relationship would survive compression.
Before using this architecture in production, teams should test it against their own documents and define what information must never be omitted. Starting with an AI PoC can help validate chunking, prompts, model selection, output quality, latency, and cost before committing to the complete system.
Walk away with actionable insights on AI adoption.
Limited seats available!



