test_combine_documents.py — langchain Source File
Architecture documentation for test_combine_documents.py, a python file in the langchain codebase. 8 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 3c91ae3f_f2e0_5cda_fe8d_6a6257bc4bbc["test_combine_documents.py"] 67ec3255_645e_8b6e_1eff_1eb3c648ed95["re"] 3c91ae3f_f2e0_5cda_fe8d_6a6257bc4bbc --> 67ec3255_645e_8b6e_1eff_1eb3c648ed95 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] 3c91ae3f_f2e0_5cda_fe8d_6a6257bc4bbc --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 120e2591_3e15_b895_72b6_cb26195e40a6["pytest"] 3c91ae3f_f2e0_5cda_fe8d_6a6257bc4bbc --> 120e2591_3e15_b895_72b6_cb26195e40a6 c554676d_b731_47b2_a98f_c1c2d537c0aa["langchain_core.documents"] 3c91ae3f_f2e0_5cda_fe8d_6a6257bc4bbc --> c554676d_b731_47b2_a98f_c1c2d537c0aa e6b4f61e_7b98_6666_3641_26b069517d4a["langchain_core.prompts"] 3c91ae3f_f2e0_5cda_fe8d_6a6257bc4bbc --> e6b4f61e_7b98_6666_3641_26b069517d4a 08fdda1e_c6d5_47d2_b46f_81d1fd43aef1["langchain_classic.chains.combine_documents.reduce"] 3c91ae3f_f2e0_5cda_fe8d_6a6257bc4bbc --> 08fdda1e_c6d5_47d2_b46f_81d1fd43aef1 43b22ac3_b13e_4978_a85f_5df267337b85["langchain_classic.chains.qa_with_sources"] 3c91ae3f_f2e0_5cda_fe8d_6a6257bc4bbc --> 43b22ac3_b13e_4978_a85f_5df267337b85 7e88f5ce_ff41_7d87_8fb2_f355489a149e["tests.unit_tests.llms.fake_llm"] 3c91ae3f_f2e0_5cda_fe8d_6a6257bc4bbc --> 7e88f5ce_ff41_7d87_8fb2_f355489a149e style 3c91ae3f_f2e0_5cda_fe8d_6a6257bc4bbc fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Test functionality related to combining documents."""
import re
from typing import Any
import pytest
from langchain_core.documents import Document
from langchain_core.prompts import PromptTemplate, aformat_document, format_document
from langchain_classic.chains.combine_documents.reduce import (
collapse_docs,
split_list_of_docs,
)
from langchain_classic.chains.qa_with_sources import load_qa_with_sources_chain
from tests.unit_tests.llms.fake_llm import FakeLLM
def _fake_docs_len_func(docs: list[Document]) -> int:
return len(_fake_combine_docs_func(docs))
def _fake_combine_docs_func(docs: list[Document], **_: Any) -> str:
return "".join([d.page_content for d in docs])
def test_multiple_input_keys() -> None:
chain = load_qa_with_sources_chain(FakeLLM(), chain_type="stuff")
assert chain.input_keys == ["input_documents", "question"]
def test__split_list_long_single_doc() -> None:
"""Test splitting of a long single doc."""
docs = [Document(page_content="foo" * 100)]
with pytest.raises(
ValueError, match="A single document was longer than the context length"
):
split_list_of_docs(docs, _fake_docs_len_func, 100)
def test__split_list_single_doc() -> None:
"""Test splitting works with just a single doc."""
docs = [Document(page_content="foo")]
doc_list = split_list_of_docs(docs, _fake_docs_len_func, 100)
assert doc_list == [docs]
def test__split_list_double_doc() -> None:
"""Test splitting works with just two docs."""
docs = [Document(page_content="foo"), Document(page_content="bar")]
doc_list = split_list_of_docs(docs, _fake_docs_len_func, 100)
assert doc_list == [docs]
def test__split_list_works_correctly() -> None:
"""Test splitting works correctly."""
docs = [
Document(page_content="foo"),
Document(page_content="bar"),
Document(page_content="baz"),
Document(page_content="foo" * 2),
// ... (100 more lines)
Domain
Subdomains
Functions
- _fake_combine_docs_func()
- _fake_docs_len_func()
- test__collapse_docs_metadata()
- test__collapse_docs_no_metadata()
- test__collapse_docs_one_doc()
- test__split_list_double_doc()
- test__split_list_long_single_doc()
- test__split_list_single_doc()
- test__split_list_works_correctly()
- test_format_doc_missing_metadata()
- test_format_doc_with_metadata()
- test_multiple_input_keys()
Dependencies
- langchain_classic.chains.combine_documents.reduce
- langchain_classic.chains.qa_with_sources
- langchain_core.documents
- langchain_core.prompts
- pytest
- re
- tests.unit_tests.llms.fake_llm
- typing
Source
Frequently Asked Questions
What does test_combine_documents.py do?
test_combine_documents.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What functions are defined in test_combine_documents.py?
test_combine_documents.py defines 12 function(s): _fake_combine_docs_func, _fake_docs_len_func, test__collapse_docs_metadata, test__collapse_docs_no_metadata, test__collapse_docs_one_doc, test__split_list_double_doc, test__split_list_long_single_doc, test__split_list_single_doc, test__split_list_works_correctly, test_format_doc_missing_metadata, and 2 more.
What does test_combine_documents.py depend on?
test_combine_documents.py imports 8 module(s): langchain_classic.chains.combine_documents.reduce, langchain_classic.chains.qa_with_sources, langchain_core.documents, langchain_core.prompts, pytest, re, tests.unit_tests.llms.fake_llm, typing.
Where is test_combine_documents.py in the architecture?
test_combine_documents.py is located at libs/langchain/tests/unit_tests/chains/test_combine_documents.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/langchain/tests/unit_tests/chains).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free