BaseCombineDocumentsChain Class — langchain Architecture
Architecture documentation for the BaseCombineDocumentsChain class in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 50b5f653_aed7_2d63_4a4b_6cf222b6a2f1["BaseCombineDocumentsChain"] 097a4781_5519_0b5d_6244_98c64eadc0d6["Chain"] 50b5f653_aed7_2d63_4a4b_6cf222b6a2f1 -->|extends| 097a4781_5519_0b5d_6244_98c64eadc0d6 0a2db3a7_355c_c29e_3859_ac2cb515d3fe["base.py"] 50b5f653_aed7_2d63_4a4b_6cf222b6a2f1 -->|defined in| 0a2db3a7_355c_c29e_3859_ac2cb515d3fe 98921d01_f287_a5ff_f4c6_ae8978d6c9c6["get_input_schema()"] 50b5f653_aed7_2d63_4a4b_6cf222b6a2f1 -->|method| 98921d01_f287_a5ff_f4c6_ae8978d6c9c6 1e4582eb_c901_ebf6_ee6a_46fce0d6c62f["get_output_schema()"] 50b5f653_aed7_2d63_4a4b_6cf222b6a2f1 -->|method| 1e4582eb_c901_ebf6_ee6a_46fce0d6c62f 403e5ddc_66f6_a015_9478_f7d04a8ce912["input_keys()"] 50b5f653_aed7_2d63_4a4b_6cf222b6a2f1 -->|method| 403e5ddc_66f6_a015_9478_f7d04a8ce912 469473d6_fe65_70fb_8bb5_2d9146507cf5["output_keys()"] 50b5f653_aed7_2d63_4a4b_6cf222b6a2f1 -->|method| 469473d6_fe65_70fb_8bb5_2d9146507cf5 76a76d07_b80c_1c69_5188_ffb5d0f8d13f["prompt_length()"] 50b5f653_aed7_2d63_4a4b_6cf222b6a2f1 -->|method| 76a76d07_b80c_1c69_5188_ffb5d0f8d13f 22fcaf59_c812_d9d2_c3b6_9281744eadc3["combine_docs()"] 50b5f653_aed7_2d63_4a4b_6cf222b6a2f1 -->|method| 22fcaf59_c812_d9d2_c3b6_9281744eadc3 51df3deb_0250_880b_3f36_8392cbb9871e["acombine_docs()"] 50b5f653_aed7_2d63_4a4b_6cf222b6a2f1 -->|method| 51df3deb_0250_880b_3f36_8392cbb9871e 7a83f4b0_7671_7d25_c77f_52d7eeba06b0["_call()"] 50b5f653_aed7_2d63_4a4b_6cf222b6a2f1 -->|method| 7a83f4b0_7671_7d25_c77f_52d7eeba06b0 4e2758dd_14b5_81d5_1e0c_e2ca334600df["_acall()"] 50b5f653_aed7_2d63_4a4b_6cf222b6a2f1 -->|method| 4e2758dd_14b5_81d5_1e0c_e2ca334600df
Relationship Graph
Source Code
libs/langchain/langchain_classic/chains/combine_documents/base.py lines 35–165
class BaseCombineDocumentsChain(Chain, ABC):
"""Base interface for chains combining documents.
Subclasses of this chain deal with combining documents in a variety of
ways. This base class exists to add some uniformity in the interface these types
of chains should expose. Namely, they expect an input key related to the documents
to use (default `input_documents`), and then also expose a method to calculate
the length of a prompt from documents (useful for outside callers to use to
determine whether it's safe to pass a list of documents into this chain or whether
that will be longer than the context length).
"""
input_key: str = "input_documents"
output_key: str = "output_text"
@override
def get_input_schema(
self,
config: RunnableConfig | None = None,
) -> type[BaseModel]:
return create_model(
"CombineDocumentsInput",
**{self.input_key: (list[Document], None)},
)
@override
def get_output_schema(
self,
config: RunnableConfig | None = None,
) -> type[BaseModel]:
return create_model(
"CombineDocumentsOutput",
**{self.output_key: (str, None)},
)
@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.output_key]
def prompt_length(self, docs: list[Document], **kwargs: Any) -> int | None: # noqa: ARG002
"""Return the prompt length given the documents passed in.
This can be used by a caller to determine whether passing in a list
of documents would exceed a certain prompt length. This useful when
trying to ensure that the size of a prompt remains below a certain
context limit.
Args:
docs: a list of documents to use to calculate the total prompt length.
**kwargs: additional parameters that may be needed to calculate the
prompt length.
Returns:
Returns None if the method does not depend on the prompt length,
otherwise the length of the prompt in tokens.
"""
return None
@abstractmethod
def combine_docs(self, docs: list[Document], **kwargs: Any) -> tuple[str, dict]:
"""Combine documents into a single string.
Args:
docs: List[Document], the documents to combine
**kwargs: Other parameters to use in combining documents, often
other inputs to the prompt.
Returns:
The first element returned is the single string output. The second
element returned is a dictionary of other keys to return.
"""
@abstractmethod
async def acombine_docs(
self,
Extends
Source
Frequently Asked Questions
What is the BaseCombineDocumentsChain class?
BaseCombineDocumentsChain is a class in the langchain codebase, defined in libs/langchain/langchain_classic/chains/combine_documents/base.py.
Where is BaseCombineDocumentsChain defined?
BaseCombineDocumentsChain is defined in libs/langchain/langchain_classic/chains/combine_documents/base.py at line 35.
What does BaseCombineDocumentsChain extend?
BaseCombineDocumentsChain extends Chain.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free