Implementation:Langchain ai Langchain VectorStoreIntegrationTests
| Knowledge Sources | |
|---|---|
| Domains | Testing, Vector Store, Standard Tests |
| Last Updated | 2026-02-11 00:00 GMT |
Overview
Standard integration test suite for validating VectorStore implementations, covering document addition, similarity search, deletion, idempotency, and get_by_ids in both sync and async modes.
Description
VectorStoreIntegrationTests is an abstract test suite class in the langchain-tests (standard-tests) package that provides comprehensive integration tests for VectorStore implementations from langchain-core. The suite tests document addition, similarity search correctness, document deletion (single and bulk), idempotent additions, mutation via overwrite, and retrieval by IDs. It includes both synchronous and asynchronous variants of each test. The suite uses DeterministicFakeEmbedding from langchain-core for deterministic, reproducible embeddings during testing.
Usage
Import VectorStoreIntegrationTests when writing integration tests for a custom VectorStore implementation to ensure it conforms to the standard vector store contract.
Code Reference
Source Location
- Repository: Langchain_ai_Langchain
- File: libs/standard-tests/langchain_tests/integration_tests/vectorstores.py
- Lines: 1-842
Signature
class VectorStoreIntegrationTests(BaseStandardTests):
@abstractmethod
@pytest.fixture
def vectorstore(self) -> VectorStore: ...
@property
def has_sync(self) -> bool: ...
@property
def has_async(self) -> bool: ...
@property
def has_get_by_ids(self) -> bool: ...
@staticmethod
def get_embeddings() -> Embeddings: ...
Import
from langchain_tests.integration_tests.vectorstores import VectorStoreIntegrationTests
I/O Contract
Inputs (Fixtures)
| Name | Type | Required | Description |
|---|---|---|---|
| vectorstore | VectorStore | Yes | An empty VectorStore instance to test. Must be empty at the start of each test. |
Configuration Properties
| Name | Type | Default | Description |
|---|---|---|---|
| has_sync | bool | True | Whether to run synchronous tests. |
| has_async | bool | True | Whether to run asynchronous tests. |
| has_get_by_ids | bool | True | Whether the VectorStore supports get_by_ids. |
Outputs
| Name | Type | Description |
|---|---|---|
| Test results | pytest outcomes | Pass/fail results for each standard test method. |
Test Methods (Sync)
| Test Method | Description |
|---|---|
| test_vectorstore_is_empty | Verifies the store starts empty (similarity_search returns []). |
| test_add_documents | Tests adding documents and verifying similarity search order. |
| test_vectorstore_still_empty | Verifies the fixture resets the store to empty between tests. |
| test_deleting_documents | Tests deletion of a single document by ID. |
| test_deleting_bulk_documents | Tests bulk deletion of multiple documents. |
| test_delete_missing_content | Verifies deleting non-existent IDs does not raise exceptions. |
| test_add_documents_with_ids_is_idempotent | Verifies adding the same documents twice with same IDs does not duplicate. |
| test_add_documents_by_id_with_mutation | Tests overwriting a document by re-adding with the same ID. |
| test_get_by_ids | Tests retrieval of documents by their IDs. |
| test_get_by_ids_missing | Tests that get_by_ids with non-existent IDs returns empty list. |
| test_add_documents_documents | Tests add_documents with auto-generated IDs and get_by_ids verification. |
| test_add_documents_with_existing_ids | Tests that Document.id field is preserved during add_documents. |
Test Methods (Async)
The async suite provides equivalent tests using aadd_documents, asimilarity_search, adelete, and aget_by_ids methods:
- test_vectorstore_is_empty_async
- test_add_documents_async
- test_vectorstore_still_empty_async
- test_deleting_documents_async
- test_deleting_bulk_documents_async
- test_delete_missing_content_async
- test_add_documents_with_ids_is_idempotent_async
- test_add_documents_by_id_with_mutation_async
- test_get_by_ids_async
- test_get_by_ids_missing_async
- test_add_documents_documents_async
- test_add_documents_with_existing_ids_async
Usage Examples
Basic Usage
from typing import Generator
import pytest
from langchain_core.vectorstores import VectorStore
from langchain_tests.integration_tests.vectorstores import VectorStoreIntegrationTests
from langchain_chroma import Chroma
class TestChromaStandard(VectorStoreIntegrationTests):
@pytest.fixture()
def vectorstore(self) -> Generator[VectorStore, None, None]:
"""Get an empty VectorStore for tests."""
store = Chroma(embedding_function=self.get_embeddings())
try:
yield store
finally:
store.delete_collection()
Disabling Async Tests
class TestMyVectorStore(VectorStoreIntegrationTests):
@pytest.fixture()
def vectorstore(self) -> Generator[VectorStore, None, None]:
...
@property
def has_async(self) -> bool:
return False
Embedding Configuration
The suite provides a get_embeddings() static method that returns a DeterministicFakeEmbedding with size 6. This produces deterministic but meaningless embeddings based on a hash of the input text. All test implementations should use this method to ensure reproducibility:
store = MyVectorStore(embedding_function=self.get_embeddings())