liveBook · Manning

MapReduce

As explained in Build AI-Enhanced Web Apps

MapReduce is a multistage processing technique that independently transforms partitions of input and then combines the intermediate results.

MapReduce is a multistage processing pattern for handling large documents. It splits input into smaller chunks, processes each chunk independently, and combines the intermediate results into one higher-level result. section 7.1.2

A document-summarization workflow typically proceeds as follows:

  • Split the document into manageable chunks, preserving some overlap so context survives chunk boundaries. section 7.1.3
  • Map each chunk independently through an LLM summarization step, producing intermediate summaries. section 7.1.2
  • Reduce the intermediate summaries by passing them through another summarization step that produces one combined overview. section 7.1.2

LangChain.js summarization chain

After loading documents and creating chunks, configure the chain with type "map_reduce" and invoke it with input_documents. Setting verbose to true enables logging while the workflow runs. section 7.1.3

Figure 7.2 The MapReduce summarization pattern, behind the scenes. The input document is divided into smaller chunks. Each chunk is then processed independently by the map function, generating intermediate summary pairs. These pairs are subsequently organized and are grouped together. The reduce step is then applied to these grouped pairs, aggregating the values to produce a final summary.

Trace the pattern visually from document chunks through independent map results, grouping, and the final reduce aggregation. section 7.1.2

MapReduce supports parallel processing and avoids sending an entire extensive document to the model in one call. Alternative summarization strategies include stuffing, which uses one call for the whole document, and refine, which updates a summary iteratively for each chunk. section 7.1.2 section 7.3

How Build AI-Enhanced Web Apps covers it

How deep it goes
Explains chunking, independent mapping, intermediate summaries, and reduction, while deferring detailed model behavior and performance tuning.
Examples
Uses large-document summarization, RecursiveCharacterTextSplitter, and a LangChain.js map_reduce chain invocation.
What it assumes
Assumes an LLM and loaded documents, while introducing chunk splitting and summarization-chain configuration.
What you can do after
Builds a large-document summarization workflow with LangChain.js by splitting documents and invoking a map_reduce chain.
How it connects
Connects document chunking, LLM summarization, LangChain.js, RAG, stuffing, and refine strategies.

Also explained in

Compare how 6 books explain MapReduce →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI-Enhanced Web Apps. The section links point to the parts of the book it draws on.