Home / Function/ _load_reduce_documents_chain() — langchain Function Reference

_load_reduce_documents_chain() — langchain Function Reference

Architecture documentation for the _load_reduce_documents_chain() function in loading.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  f01823ee_2304_5ece_d221_f5016c463bd7["_load_reduce_documents_chain()"]
  61dd5a0b_3bf7_b973_6dac_edfd465b21fb["loading.py"]
  f01823ee_2304_5ece_d221_f5016c463bd7 -->|defined in| 61dd5a0b_3bf7_b973_6dac_edfd465b21fb
  30094e71_1495_af51_d93f_0de6d110da9d["_load_map_reduce_documents_chain()"]
  30094e71_1495_af51_d93f_0de6d110da9d -->|calls| f01823ee_2304_5ece_d221_f5016c463bd7
  7c915b91_f326_1908_9969_d0cb1f4f7e34["load_chain_from_config()"]
  f01823ee_2304_5ece_d221_f5016c463bd7 -->|calls| 7c915b91_f326_1908_9969_d0cb1f4f7e34
  ab90e794_4e78_646b_dee9_e87a00250d94["load_chain()"]
  f01823ee_2304_5ece_d221_f5016c463bd7 -->|calls| ab90e794_4e78_646b_dee9_e87a00250d94
  style f01823ee_2304_5ece_d221_f5016c463bd7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/chains/loading.py lines 185–251

def _load_reduce_documents_chain(config: dict, **kwargs: Any) -> ReduceDocumentsChain:
    combine_documents_chain = None
    collapse_documents_chain = None

    if "combine_documents_chain" in config:
        combine_document_chain_config = config.pop("combine_documents_chain")
        combine_documents_chain = load_chain_from_config(
            combine_document_chain_config,
            **kwargs,
        )
    elif "combine_document_chain" in config:
        combine_document_chain_config = config.pop("combine_document_chain")
        combine_documents_chain = load_chain_from_config(
            combine_document_chain_config,
            **kwargs,
        )
    elif "combine_documents_chain_path" in config:
        combine_documents_chain = load_chain(
            config.pop("combine_documents_chain_path"),
            **kwargs,
        )
    elif "combine_document_chain_path" in config:
        combine_documents_chain = load_chain(
            config.pop("combine_document_chain_path"),
            **kwargs,
        )
    else:
        msg = (
            "One of `combine_documents_chain` or "
            "`combine_documents_chain_path` must be present."
        )
        raise ValueError(msg)

    if "collapse_documents_chain" in config:
        collapse_document_chain_config = config.pop("collapse_documents_chain")
        if collapse_document_chain_config is None:
            collapse_documents_chain = None
        else:
            collapse_documents_chain = load_chain_from_config(
                collapse_document_chain_config,
                **kwargs,
            )
    elif "collapse_documents_chain_path" in config:
        collapse_documents_chain = load_chain(
            config.pop("collapse_documents_chain_path"),
            **kwargs,
        )
    elif "collapse_document_chain" in config:
        collapse_document_chain_config = config.pop("collapse_document_chain")
        if collapse_document_chain_config is None:
            collapse_documents_chain = None
        else:
            collapse_documents_chain = load_chain_from_config(
                collapse_document_chain_config,
                **kwargs,
            )
    elif "collapse_document_chain_path" in config:
        collapse_documents_chain = load_chain(
            config.pop("collapse_document_chain_path"),
            **kwargs,
        )

    return ReduceDocumentsChain(
        combine_documents_chain=combine_documents_chain,
        collapse_documents_chain=collapse_documents_chain,
        **config,
    )

Subdomains

Frequently Asked Questions

What does _load_reduce_documents_chain() do?
_load_reduce_documents_chain() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/chains/loading.py.
Where is _load_reduce_documents_chain() defined?
_load_reduce_documents_chain() is defined in libs/langchain/langchain_classic/chains/loading.py at line 185.
What does _load_reduce_documents_chain() call?
_load_reduce_documents_chain() calls 2 function(s): load_chain, load_chain_from_config.
What calls _load_reduce_documents_chain()?
_load_reduce_documents_chain() is called by 1 function(s): _load_map_reduce_documents_chain.

Analyze Your Own Codebase

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

Try Supermodel Free