.md
.pdf
CombineDocuments Chains
 Contents 
Stuffing
Map Reduce
Refine
Map-Rerank
CombineDocuments Chains#
CombineDocuments chains are useful for when you need to run a language over multiple documents.
Common use cases for this include question answering, question answering with sources, summarization, and more.
For more information on specific use cases as well as different methods for fetching these documents, please see
this overview.
This documentation now picks up from after you’ve fetched your documents - now what?
How do you pass them to the language model in a format it can understand?
There are a few different methods, or chains, for doing so. LangChain supports four of the more common ones - and
we are actively looking to include more, so if you have any ideas please reach out! Note that there is not
one best method - the decision of which one to use is often very context specific. In order from simplest to
most complex:
Stuffing#
Stuffing is the simplest method, whereby you simply stuff all the related data into the prompt as context
to pass to the language model. This is implemented in LangChain as the StuffDocumentsChain.
Pros: Only makes a single call to the LLM. When generating text, the LLM has access to all the data at once.
Cons: Most LLMs have a context length, and for large documents (or many documents) this will not work as it will result in a prompt larger than the context length.
The main downside of this method is that it only works on smaller pieces of data. Once you are working
with many pieces of data, this approach is no longer feasible. The next two approaches are designed to help deal with that.
Map Reduce#
This method involves running an initial prompt on each chunk of data (for summarization tasks, this