LangChain provides four main document chain strategies: Stuff (simple concatenation), MapReduce (parallel processing with summarization), Refine (iterative refinement), and MapRerank (scored selection). They differ in how they handle multiple documents, balancing token usage, latency, and quality.
LangChain's document chains are methods for processing multiple documents in a QA pipeline. The Stuff chain simply concatenates all documents into a single prompt, which is fast but limited by the LLM's context window. MapReduce processes each document in parallel (Map step) and then combines the results (Reduce step), suitable for large document sets but requires more API calls. Refine iteratively updates an answer by processing documents sequentially, preserving context but being slower. MapRerank runs an initial prompt to generate an answer and confidence score for each document, then selects the best one; it's useful when you need a single high-quality answer but can be expensive.[reference:0][reference:1]
Stuff: Use for < 5 short documents where total token count fits within the model's context window. Fastest, lowest cost, but limited capacity.
MapReduce: Use for large document collections (e.g., 20+ pages). Parallel processing reduces latency, but final answer may lose nuance across documents.
Refine: Use when sequential reasoning is important (e.g., legal analysis, complex research). Preserves context but has higher latency.
MapRerank: Use when you need the single best answer from a set of documents (e.g., fact lookup, customer support). Provides confidence scores but is expensive.
You need to pull three short paragraphs from a vector store and send them as a single prompt to an LLM. Which chain strategy would you pick and why?
If you mistakenly used a MapRerank chain to just concatenate two documents, what would the LLM see and why might that be a problem?
Describe how you would configure a Stuff chain to combine the titles of five retrieved articles into one input string.
Our feature first retrieves ten docs, filters out low‑score ones, then ranks the remaining before passing them to the model. Which combination of Stuff, MapReduce, Refine, and MapRerank would you choose and what trade‑offs are you making?
During a beta rollout the Refine chain started returning duplicated sentences in the final answer. How would you go about debugging that behavior?
Explain why you might prefer MapReduce over MapRerank when each document needs a costly summarization step before aggregation.
Design a high‑throughput RAG service that must summarize large documents and then rank the summaries for each query. Which chain strategies would you compose, and how would you orchestrate them to keep latency low?
Compare the memory and latency impact of using a Stuff chain versus a MapReduce chain when processing a 100‑page corpus per request.
If you need to insert a new post‑processing filter into an existing Refine‑based pipeline without breaking downstream components, how would you refactor the chain?
Our platform is moving from a monolithic RAG implementation that relies heavily on Stuff chains to a microservice‑based architecture. How would you restructure the chain strategies across services and plan the migration?
Discuss long‑term maintainability when multiple teams share a library that mixes MapReduce and MapRerank patterns. What guidelines would you establish?
Given a roadmap that deprecates the Refine pattern in favor of newer LangChain primitives, how would you evaluate the impact and orchestrate a phased rollout across the organization?