Implementation:Langchain ai Langchain IndexerTests
| Knowledge Sources | |
|---|---|
| Domains | Testing, Document Indexing, Standard Tests |
| Last Updated | 2026-02-11 00:00 GMT |
Overview
Standard integration test suites for validating synchronous and asynchronous implementations of the LangChain DocumentIndex abstraction.
Description
This module provides two abstract test suite classes -- DocumentIndexerTestSuite and AsyncDocumentIndexTestSuite -- in the langchain-tests (standard-tests) package. They verify that implementations of DocumentIndex from langchain-core correctly support document upsert, retrieval by ID, deletion, and overwriting operations. Implementers subclass one or both suites and provide a pytest fixture that yields an empty DocumentIndex instance.
Usage
Import DocumentIndexerTestSuite or AsyncDocumentIndexTestSuite when writing integration tests for a custom DocumentIndex implementation to ensure it conforms to the standard document indexing contract.
Code Reference
Source Location
- Repository: Langchain_ai_Langchain
- File: libs/standard-tests/langchain_tests/integration_tests/indexer.py
- Lines: 1-398
Signature
class DocumentIndexerTestSuite(ABC):
@abstractmethod
@pytest.fixture
def index(self) -> Generator[DocumentIndex, None, None]: ...
class AsyncDocumentIndexTestSuite(ABC):
@abstractmethod
@pytest.fixture
async def index(self) -> AsyncGenerator[DocumentIndex, None]: ...
Import
from langchain_tests.integration_tests.indexer import (
DocumentIndexerTestSuite,
AsyncDocumentIndexTestSuite,
)
I/O Contract
Inputs (Fixtures)
| Name | Type | Required | Description |
|---|---|---|---|
| index | DocumentIndex | Yes | An empty DocumentIndex instance to test. Must be empty at the start of each test. |
Outputs
| Name | Type | Description |
|---|---|---|
| Test results | pytest outcomes | Pass/fail results for each standard test method. |
Test Methods (DocumentIndexerTestSuite)
| Test Method | Description |
|---|---|
| test_upsert_documents_has_no_ids | Verifies the upsert method signature does not include an "ids" parameter. |
| test_upsert_no_ids | Tests upserting documents that do not have pre-assigned IDs. |
| test_upsert_some_ids | Tests upserting a mix of documents with and without IDs. |
| test_upsert_overwrites | Tests that upsert overwrites existing content for the same document ID. |
| test_delete_missing_docs | Verifies deleting non-existent documents does not raise exceptions and returns correct response. |
| test_delete_semantics | Tests that delete correctly removes one document while reporting missing IDs correctly. |
| test_bulk_delete | Tests deletion of multiple documents at once. |
| test_delete_no_args | Tests that delete with no arguments raises ValueError. |
| test_delete_missing_content | Tests that deleting missing content does not raise exceptions. |
| test_get_with_missing_ids | Tests retrieval when some requested IDs do not exist. |
| test_get_missing | Tests retrieval when none of the requested IDs exist. |
Test Methods (AsyncDocumentIndexTestSuite)
The async suite mirrors the sync suite with equivalent tests using aupsert, aget, and adelete async methods.
Usage Examples
Basic Usage
import pytest
from collections.abc import Generator
from langchain_core.indexing.base import DocumentIndex
from langchain_tests.integration_tests.indexer import DocumentIndexerTestSuite
from my_package.indexers import MyDocumentIndex
class TestMyDocumentIndex(DocumentIndexerTestSuite):
@pytest.fixture
def index(self) -> Generator[DocumentIndex, None, None]:
idx = MyDocumentIndex()
try:
yield idx
finally:
idx.clear()