DocumentIndexerTestSuite Class — langchain Architecture
Architecture documentation for the DocumentIndexerTestSuite class in indexer.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 67ebaa9c_263d_69d9_3a75_de0b0ac61588["DocumentIndexerTestSuite"] 5a4b621f_3b0b_0a99_5749_01a0dccd1543["indexer.py"] 67ebaa9c_263d_69d9_3a75_de0b0ac61588 -->|defined in| 5a4b621f_3b0b_0a99_5749_01a0dccd1543 3c2d210d_a084_52db_d615_af6023078a6c["index()"] 67ebaa9c_263d_69d9_3a75_de0b0ac61588 -->|method| 3c2d210d_a084_52db_d615_af6023078a6c 678a7e42_92d0_4000_95e5_06be40830aec["test_upsert_documents_has_no_ids()"] 67ebaa9c_263d_69d9_3a75_de0b0ac61588 -->|method| 678a7e42_92d0_4000_95e5_06be40830aec bcc0bfb4_2e20_58e4_72b0_77bd6a490074["test_upsert_no_ids()"] 67ebaa9c_263d_69d9_3a75_de0b0ac61588 -->|method| bcc0bfb4_2e20_58e4_72b0_77bd6a490074 eb110bf4_53df_a3eb_901c_b50b5867670d["test_upsert_some_ids()"] 67ebaa9c_263d_69d9_3a75_de0b0ac61588 -->|method| eb110bf4_53df_a3eb_901c_b50b5867670d 55e9955a_6054_786f_ce69_5fd8209628dc["test_upsert_overwrites()"] 67ebaa9c_263d_69d9_3a75_de0b0ac61588 -->|method| 55e9955a_6054_786f_ce69_5fd8209628dc 6a3f3e5a_f55a_017e_2d84_11aafdceeb0e["test_delete_missing_docs()"] 67ebaa9c_263d_69d9_3a75_de0b0ac61588 -->|method| 6a3f3e5a_f55a_017e_2d84_11aafdceeb0e 4f77aa21_f1d2_a900_2b5a_09480ff46f6a["test_delete_semantics()"] 67ebaa9c_263d_69d9_3a75_de0b0ac61588 -->|method| 4f77aa21_f1d2_a900_2b5a_09480ff46f6a 0215bbdf_fee9_5b4b_4d4a_c20b15c24242["test_bulk_delete()"] 67ebaa9c_263d_69d9_3a75_de0b0ac61588 -->|method| 0215bbdf_fee9_5b4b_4d4a_c20b15c24242 4bb5abe8_b8d7_8ee3_d1f6_796896f49d0f["test_delete_no_args()"] 67ebaa9c_263d_69d9_3a75_de0b0ac61588 -->|method| 4bb5abe8_b8d7_8ee3_d1f6_796896f49d0f 09f03bc0_b715_73e1_4cea_b915021ba52d["test_delete_missing_content()"] 67ebaa9c_263d_69d9_3a75_de0b0ac61588 -->|method| 09f03bc0_b715_73e1_4cea_b915021ba52d 0662580e_d4ff_5584_1da0_95133158bf88["test_get_with_missing_ids()"] 67ebaa9c_263d_69d9_3a75_de0b0ac61588 -->|method| 0662580e_d4ff_5584_1da0_95133158bf88 dc95d2a4_9e68_82c2_6926_32f8513295cc["test_get_missing()"] 67ebaa9c_263d_69d9_3a75_de0b0ac61588 -->|method| dc95d2a4_9e68_82c2_6926_32f8513295cc
Relationship Graph
Source Code
libs/standard-tests/langchain_tests/integration_tests/indexer.py lines 19–206
class DocumentIndexerTestSuite(ABC):
"""Test suite for checking the read-write of a document index.
Implementers should subclass this test suite and provide a fixture that returns an
empty index for each test.
"""
@abstractmethod
@pytest.fixture
def index(self) -> Generator[DocumentIndex, None, None]:
"""Get the index."""
def test_upsert_documents_has_no_ids(self, index: DocumentIndex) -> None:
"""Verify that there is no parameter called IDs in upsert."""
signature = inspect.signature(index.upsert)
assert "ids" not in signature.parameters
def test_upsert_no_ids(self, index: DocumentIndex) -> None:
"""Upsert works with documents that do not have IDs.
At the moment, the ID field in documents is optional.
"""
documents = [
Document(page_content="foo", metadata={"id": 1}),
Document(page_content="bar", metadata={"id": 2}),
]
response = index.upsert(documents)
ids = sorted(response["succeeded"])
# Ordering is not guaranteed, need to test carefully
documents = index.get(ids)
sorted_documents = sorted(documents, key=lambda x: x.id or "")
if sorted_documents[0].page_content == "bar":
assert sorted_documents[0] == Document(
page_content="bar", metadata={"id": 2}, id=ids[0]
)
assert sorted_documents[1] == Document(
page_content="foo", metadata={"id": 1}, id=ids[1]
)
else:
assert sorted_documents[0] == Document(
page_content="foo", metadata={"id": 1}, id=ids[0]
)
assert sorted_documents[1] == Document(
page_content="bar", metadata={"id": 2}, id=ids[1]
)
def test_upsert_some_ids(self, index: DocumentIndex) -> None:
"""Test an upsert where some docs have IDs and some don't."""
foo_uuid = str(uuid.UUID(int=7))
documents = [
Document(id=foo_uuid, page_content="foo", metadata={"id": 1}),
Document(page_content="bar", metadata={"id": 2}),
]
response = index.upsert(documents)
ids = response["succeeded"]
other_id = next(iter(set(ids) - {foo_uuid}))
assert response["failed"] == []
assert foo_uuid in ids
# Ordering is not guaranteed, so we use a set.
documents = index.get(ids)
first_doc = documents[0]
if first_doc.id == foo_uuid:
assert documents == [
Document(page_content="foo", metadata={"id": 1}, id=foo_uuid),
Document(page_content="bar", metadata={"id": 2}, id=other_id),
]
else:
assert documents == [
Document(page_content="bar", metadata={"id": 2}, id=other_id),
Document(page_content="foo", metadata={"id": 1}, id=foo_uuid),
]
def test_upsert_overwrites(self, index: DocumentIndex) -> None:
"""Test that upsert overwrites existing content."""
foo_uuid = str(uuid.UUID(int=7))
documents = [
Document(id=foo_uuid, page_content="foo", metadata={"bar": 1}),
]
response = index.upsert(documents)
Source
Frequently Asked Questions
What is the DocumentIndexerTestSuite class?
DocumentIndexerTestSuite is a class in the langchain codebase, defined in libs/standard-tests/langchain_tests/integration_tests/indexer.py.
Where is DocumentIndexerTestSuite defined?
DocumentIndexerTestSuite is defined in libs/standard-tests/langchain_tests/integration_tests/indexer.py at line 19.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free