liveBook · Manning

MapReduce

As explained in AI Agents and Applications

MapReduce is a processing pattern that independently transforms chunks and then combines the partial results into a final result.

MapReduce processes data in two stages: independently transform smaller chunks, then combine the partial results into one final result. For large-language-model summarization, it keeps each prompt within the model’s context window. section 3.1.3 section 3.1

A document summarization pipeline typically works as follows:

  • Split the document into token-sized chunks with a tokenizer such as TokenTextSplitter. section 3.1
  • Map the same summarization chain over every chunk, independently and in parallel. section 3.1.3
  • Reduce the intermediate summaries into a final summary. section 3.1.3

Summarizing a large report

A 100-page report is split into chunks, summarized separately, and then condensed from those partial summaries. This supports parallel processing and lower token costs, but may lose contextual connections between sections. section 3.4

A LangChain implementation composes a prompt, language model, and StrOutputParser with the pipe operator, then uses RunnableParallel to apply the map chain across chunks. Across multiple documents, each Document becomes an intermediate summary before reduction. section 3.1.3 section 3.2

Figure 3.1 Summarizing a document bigger than the LLM’s context window involves splitting the document into smaller chunks, summarizing each chunk, and then summarizing the combined chunk summaries.
figure

Shows the complete flow from splitting an oversized document through chunk summaries to the final combined summary. section 3.1

Choose MapReduce when the input exceeds the context window and parallel speed matters more than preserving every contextual connection. Use refine instead when each document’s essence must be retained; refine processes chunks sequentially and updates a running summary. section 3.2 section 3.3

How AI Agents and Applications covers it

How deep it goes
Explains chunking, parallel mapping, reduction, LangChain composition, and trade-offs, but not distributed-system execution internals.
Examples
Uses oversized documents, 100-page reports, multiple Document objects, chunk prompts, and RunnableParallel chains.
What it assumes
Assumes basic prompts and language-model calls while introducing tokenization, context limits, document chunks, and chain composition.
What you can do after
Build it from scratch with LangChain by splitting text, mapping a summarization chain, and reducing intermediate summaries.
How it connects
Connects context windows, tokenization, summarization, parallel processing, LangChain, and the refine technique.

Also explained in

Compare how 6 books explain MapReduce →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Agents and Applications. The section links point to the parts of the book it draws on.