Process document libraries that exceed context windows using sliding chunk schemas.
01 The Concept
When document libraries exceed the model's context window, sliding window chunking splits the text into overlapping segments, processes each chunk with local summarizations, and aggregates the results using a hierarchical map-reduce prompt structure.
02 Weak vs. Strong
EX 01Map-Reduce Chunking Pipeline (Python)
# 1. Split text into chunks with 200-word overlap
chunks = split_text(large_text, size=2000, overlap=200)
# 2. Map: extract facts in parallel
local_summaries = [call_llm(f"Extract facts: {c}") for c in chunks]
# 3. Reduce: compile final summary
final_summary = call_llm("Combine summaries:\n" + "\n".join(local_summaries))
→ Why it works
Systematically bypasses context constraints. Mapping extracts localized data, and reducing aggregates them, protecting pipelines from token crashes.
03 Key Points
01Sliding Windows: Splitting documents into segments with 10-20% overlap to preserve context.
02Map Step: Running local prompts on each chunk to extract key facts or summaries.
03Reduce Step: Fusing chunk summaries into a single cohesive final document.
04Chunk Overlap: Preventing loss of information at chunk boundaries.
05Context Limits: Enforcing systematic data flow when documents exceed model limits.
04 Model-Specific Notes
Claude handles local maps with high extraction precision. XML tag parameters help keep segment summaries distinct.
05 For Your Role
It's like summarizing a thick book chapter-by-chapter, and then writing a one-page summary based on those chapter notes.