Home / Function/ combine_docs() — langchain Function Reference

combine_docs() — langchain Function Reference

Architecture documentation for the combine_docs() function in map_reduce.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  4e67fd44_4186_539a_6afa_914286d20763["combine_docs()"]
  a22a5836_e793_27ca_7ffe_21cb92057ad5["MapReduceDocumentsChain"]
  4e67fd44_4186_539a_6afa_914286d20763 -->|defined in| a22a5836_e793_27ca_7ffe_21cb92057ad5
  style 4e67fd44_4186_539a_6afa_914286d20763 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/chains/combine_documents/map_reduce.py lines 224–256

    def combine_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 = self.llm_chain.apply(
            # 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 = self.reduce_documents_chain.combine_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

Subdomains

Frequently Asked Questions

What does combine_docs() do?
combine_docs() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/chains/combine_documents/map_reduce.py.
Where is combine_docs() defined?
combine_docs() is defined in libs/langchain/langchain_classic/chains/combine_documents/map_reduce.py at line 224.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free