acombine_docs() — langchain Function Reference
Architecture documentation for the acombine_docs() function in map_reduce.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 4f1d63c6_7238_99c2_c621_b153dda81409["acombine_docs()"] a22a5836_e793_27ca_7ffe_21cb92057ad5["MapReduceDocumentsChain"] 4f1d63c6_7238_99c2_c621_b153dda81409 -->|defined in| a22a5836_e793_27ca_7ffe_21cb92057ad5 style 4f1d63c6_7238_99c2_c621_b153dda81409 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/langchain_classic/chains/combine_documents/map_reduce.py lines 258–290
async def acombine_docs(
self,
docs: list[Document],
token_max: int | None = None,
callbacks: Callbacks = None,
**kwargs: Any,
) -> tuple[str, dict]:
"""Combine documents in a map reduce manner.
Combine by mapping first chain over all documents, then reducing the results.
This reducing can be done recursively if needed (if there are many documents).
"""
map_results = await self.llm_chain.aapply(
# FYI - this is parallelized and so it is fast.
[{self.document_variable_name: d.page_content, **kwargs} for d in docs],
callbacks=callbacks,
)
question_result_key = self.llm_chain.output_key
result_docs = [
Document(page_content=r[question_result_key], metadata=docs[i].metadata)
# This uses metadata from the docs, and the textual results from `results`
for i, r in enumerate(map_results)
]
result, extra_return_dict = await self.reduce_documents_chain.acombine_docs(
result_docs,
token_max=token_max,
callbacks=callbacks,
**kwargs,
)
if self.return_intermediate_steps:
intermediate_steps = [r[question_result_key] for r in map_results]
extra_return_dict["intermediate_steps"] = intermediate_steps
return result, extra_return_dict
Domain
Subdomains
Source
Frequently Asked Questions
What does acombine_docs() do?
acombine_docs() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/chains/combine_documents/map_reduce.py.
Where is acombine_docs() defined?
acombine_docs() is defined in libs/langchain/langchain_classic/chains/combine_documents/map_reduce.py at line 258.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free