acollapse_docs() — langchain Function Reference
Architecture documentation for the acollapse_docs() function in reduce.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD cc0b587b_d269_c999_d5cc_a08dd506562c["acollapse_docs()"] c47d011a_bcd5_947b_be68_ac5c423fea9d["reduce.py"] cc0b587b_d269_c999_d5cc_a08dd506562c -->|defined in| c47d011a_bcd5_947b_be68_ac5c423fea9d 4961cdaa_eb66_8549_74f5_80aa6ef431de["_acollapse()"] 4961cdaa_eb66_8549_74f5_80aa6ef431de -->|calls| cc0b587b_d269_c999_d5cc_a08dd506562c style cc0b587b_d269_c999_d5cc_a08dd506562c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/langchain_classic/chains/combine_documents/reduce.py lines 99–128
async def acollapse_docs(
docs: list[Document],
combine_document_func: AsyncCombineDocsProtocol,
**kwargs: Any,
) -> Document:
"""Execute a collapse function on a set of documents and merge their metadatas.
Args:
docs: A list of `Document` objects to combine.
combine_document_func: A function that takes in a list of `Document` objects and
optionally addition keyword parameters and combines them into a single
string.
**kwargs: Arbitrary additional keyword params to pass to the
`combine_document_func`.
Returns:
A single `Document` with the output of `combine_document_func` for the page
content and the combined metadata's of all the input documents. All metadata
values are strings, and where there are overlapping keys across documents
the values are joined by `', '`.
"""
result = await combine_document_func(docs, **kwargs)
combined_metadata = {k: str(v) for k, v in docs[0].metadata.items()}
for doc in docs[1:]:
for k, v in doc.metadata.items():
if k in combined_metadata:
combined_metadata[k] += f", {v}"
else:
combined_metadata[k] = str(v)
return Document(page_content=result, metadata=combined_metadata)
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does acollapse_docs() do?
acollapse_docs() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/chains/combine_documents/reduce.py.
Where is acollapse_docs() defined?
acollapse_docs() is defined in libs/langchain/langchain_classic/chains/combine_documents/reduce.py at line 99.
What calls acollapse_docs()?
acollapse_docs() is called by 1 function(s): _acollapse.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free