Home / Class/ AnalyzeDocumentChain Class — langchain Architecture

AnalyzeDocumentChain Class — langchain Architecture

Architecture documentation for the AnalyzeDocumentChain class in base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  6967363b_5687_0df1_ea75_11e5aee145da["AnalyzeDocumentChain"]
  f3cef70e_11b0_61c9_7ec0_7308f4b45056["Chain"]
  6967363b_5687_0df1_ea75_11e5aee145da -->|extends| f3cef70e_11b0_61c9_7ec0_7308f4b45056
  ab0b7396_014e_9570_8f95_c492a9ffc94b["base.py"]
  6967363b_5687_0df1_ea75_11e5aee145da -->|defined in| ab0b7396_014e_9570_8f95_c492a9ffc94b
  c6b2d7eb_b287_ce29_c82c_7ae149802b51["input_keys()"]
  6967363b_5687_0df1_ea75_11e5aee145da -->|method| c6b2d7eb_b287_ce29_c82c_7ae149802b51
  cfb1ec14_0580_8db7_24ee_93517fe4d8ff["output_keys()"]
  6967363b_5687_0df1_ea75_11e5aee145da -->|method| cfb1ec14_0580_8db7_24ee_93517fe4d8ff
  afdaaf63_cfee_8c11_f9f7_973aaefd26cb["get_input_schema()"]
  6967363b_5687_0df1_ea75_11e5aee145da -->|method| afdaaf63_cfee_8c11_f9f7_973aaefd26cb
  64fec5aa_5eec_fc5d_3806_540e4d1252a7["get_output_schema()"]
  6967363b_5687_0df1_ea75_11e5aee145da -->|method| 64fec5aa_5eec_fc5d_3806_540e4d1252a7
  2935460b_bf17_a686_f1f0_6e58ef3057d8["_call()"]
  6967363b_5687_0df1_ea75_11e5aee145da -->|method| 2935460b_bf17_a686_f1f0_6e58ef3057d8

Relationship Graph

Source Code

libs/langchain/langchain_classic/chains/combine_documents/base.py lines 176–278

class AnalyzeDocumentChain(Chain):
    """Chain that splits documents, then analyzes it in pieces.

    This chain is parameterized by a TextSplitter and a CombineDocumentsChain.
    This chain takes a single document as input, and then splits it up into chunks
    and then passes those chucks to the CombineDocumentsChain.

    This class is deprecated. See below for alternative implementations which
    supports async and streaming modes of operation.

    If the underlying combine documents chain takes one `input_documents` argument
    (e.g., chains generated by `load_summarize_chain`):

        ```python
        split_text = lambda x: text_splitter.create_documents([x])

        summarize_document_chain = split_text | chain
        ```

    If the underlying chain takes additional arguments (e.g., `load_qa_chain`, which
    takes an additional `question` argument), we can use the following:

        ```python
        from operator import itemgetter
        from langchain_core.runnables import RunnableLambda, RunnableParallel

        split_text = RunnableLambda(lambda x: text_splitter.create_documents([x]))
        summarize_document_chain = RunnableParallel(
            question=itemgetter("question"),
            input_documents=itemgetter("input_document") | split_text,
        ) | chain.pick("output_text")
        ```

    To additionally return the input parameters, as `AnalyzeDocumentChain` does,
    we can wrap this construction with `RunnablePassthrough`:

        ```python
        from operator import itemgetter
        from langchain_core.runnables import (
            RunnableLambda,
            RunnableParallel,
            RunnablePassthrough,
        )

        split_text = RunnableLambda(lambda x: text_splitter.create_documents([x]))
        summarize_document_chain = RunnablePassthrough.assign(
            output_text=RunnableParallel(
                question=itemgetter("question"),
                input_documents=itemgetter("input_document") | split_text,
            )
            | chain.pick("output_text")
        )
        ```
    """

    input_key: str = "input_document"
    text_splitter: TextSplitter = Field(default_factory=RecursiveCharacterTextSplitter)
    combine_docs_chain: BaseCombineDocumentsChain

    @property
    def input_keys(self) -> list[str]:
        """Expect input key."""
        return [self.input_key]

    @property
    def output_keys(self) -> list[str]:
        """Return output key."""
        return self.combine_docs_chain.output_keys

    @override
    def get_input_schema(
        self,
        config: RunnableConfig | None = None,
    ) -> type[BaseModel]:
        return create_model(
            "AnalyzeDocumentChain",
            **{self.input_key: (str, None)},
        )

    @override
    def get_output_schema(

Extends

Frequently Asked Questions

What is the AnalyzeDocumentChain class?
AnalyzeDocumentChain is a class in the langchain codebase, defined in libs/langchain/langchain_classic/chains/combine_documents/base.py.
Where is AnalyzeDocumentChain defined?
AnalyzeDocumentChain is defined in libs/langchain/langchain_classic/chains/combine_documents/base.py at line 176.
What does AnalyzeDocumentChain extend?
AnalyzeDocumentChain extends Chain.

Analyze Your Own Codebase

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

Try Supermodel Free