Vector Store Adapters

The adapters layer provides concrete wrappers around different vector database clients (Chroma, PGVector, Milvus). It allows the synchronization pipeline to write to any vector store using a unified interface.

Base Interface

VectorStoreAdapter

Abstract interface for vector store backends.

Abstract VectorStoreAdapter — the contract all backends must implement.

Keeping this boundary explicit means:
  1. SyncManager has no knowledge of which backend is in use.

  2. New backends require only implementing three methods.

  3. Contract tests can verify any adapter against this interface.

class VectorStoreAdapter[source]

Bases: ABC

Abstract interface for vector store backends.

Each backend wraps a LangChain VectorStore and exposes the three operations the SyncManager needs: upsert, delete, and as_retriever.

abstract upsert(document)[source]

Add or replace a document in the vector store.

The implementation should use the document.id field as the canonical identifier for idempotent upserts.

Parameters:

document (Document)

Return type:

None

abstract upsert_batch(documents)[source]

Add or replace a list of documents in the vector store.

The implementation should use each document.id field as the canonical identifier for idempotent upserts.

Parameters:

documents (list[Document])

Return type:

None

abstract delete(doc_id)[source]

Remove a document by its stable ID.

Implementations must handle the case where the ID does not exist (e.g. soft-delete stores, delete events arriving before inserts).

Parameters:

doc_id (str)

Return type:

None

abstract delete_batch(doc_ids)[source]

Remove a list of documents by their stable IDs in bulk.

Implementations must handle the case where the IDs do not exist.

Parameters:

doc_ids (list[str])

Return type:

None

abstract as_retriever(*, metadata_filter=None, **kwargs)[source]

Return a LangChain BaseRetriever backed by this vector store.

Parameters:
Return type:

BaseRetriever

Vector Database Implementations

ChromaAdapter

Vector store adapter for ChromaDB.

PGVectorAdapter

Vector store adapter for PGVector (PostgreSQL).

MilvusAdapter

Vector store adapter for Milvus.

Chroma vector store adapter implementation.

class ChromaAdapter(collection_name, embeddings, persist_directory=None, **kwargs)[source]

Bases: VectorStoreAdapter

Vector store adapter for ChromaDB.

Parameters:
  • collection_name (str)

  • embeddings (Embeddings)

  • persist_directory (str | None)

  • kwargs (Any)

__init__(collection_name, embeddings, persist_directory=None, **kwargs)[source]

Initialises the ChromaAdapter.

Parameters:
  • collection_name (str) – Name of the Chroma collection.

  • embeddings (Embeddings) – Embeddings model to generate vector representations.

  • persist_directory (str | None) – Directory to persist Chroma database files.

  • **kwargs (Any) – Additional arguments forwarded to the Chroma vector store.

Return type:

None

upsert(document)[source]

Add or replace a document in the vector store.

Parameters:

document (Document) – The LangChain Document to upsert.

Return type:

None

upsert_batch(documents)[source]

Add or replace a list of documents in the vector store.

Parameters:

documents (list[Document]) – The list of LangChain Documents to upsert.

Return type:

None

delete(doc_id)[source]

Remove a document by its stable ID.

Parameters:

doc_id (str) – The stable ID of the document to remove.

Return type:

None

delete_batch(doc_ids)[source]

Remove a list of documents by their stable IDs in bulk.

Parameters:

doc_ids (list[str]) – The stable IDs of the documents to remove.

Return type:

None

as_retriever(*, metadata_filter=None, **kwargs)[source]

Return a LangChain BaseRetriever backed by this vector store.

Parameters:
  • metadata_filter (dict[str, Any] | None) – Optional dictionary of metadata key-values to filter by.

  • **kwargs (Any) – Options for the retriever (e.g. search_kwargs={“k”: 5}).

Returns:

A LangChain BaseRetriever.

Return type:

BaseRetriever

PGVector vector store adapter implementation.

class PGVectorAdapter(connection_string, collection_name, embeddings, pre_delete_collection=False)[source]

Bases: VectorStoreAdapter

Vector store adapter for PGVector (PostgreSQL).

Parameters:
  • connection_string (str)

  • collection_name (str)

  • embeddings (Embeddings)

  • pre_delete_collection (bool)

__init__(connection_string, collection_name, embeddings, pre_delete_collection=False)[source]

Initialises the PGVectorAdapter.

Parameters:
  • connection_string (str) – SQLAlchemy async connection URL.

  • collection_name (str) – Table name for this embedding collection.

  • embeddings (Embeddings) – Embeddings model to generate vector representations.

  • pre_delete_collection (bool) – Drop and recreate collection on init (default False).

Return type:

None

upsert(document)[source]

Add or replace a document in the vector store.

Parameters:

document (Document) – The LangChain Document to upsert.

Return type:

None

upsert_batch(documents)[source]

Add or replace a list of documents in the vector store.

Parameters:

documents (list[Document]) – The list of LangChain Documents to upsert.

Return type:

None

delete(doc_id)[source]

Remove a document by its stable ID.

Parameters:

doc_id (str) – The stable ID of the document to remove.

Return type:

None

delete_batch(doc_ids)[source]

Remove a list of documents by their stable IDs in bulk.

Parameters:

doc_ids (list[str]) – The stable IDs of the documents to remove.

Return type:

None

as_retriever(*, metadata_filter=None, **kwargs)[source]

Return a LangChain BaseRetriever backed by this vector store.

Parameters:
  • metadata_filter (dict[str, Any] | None) – Optional dictionary of metadata key-values to filter by.

  • **kwargs (Any) – Options for the retriever (e.g. search_kwargs={“k”: 5}).

Returns:

A LangChain BaseRetriever.

Return type:

BaseRetriever

property store: Any

Direct access to the underlying langchain_postgres.PGVector instance.

Milvus vector store adapter implementation.

class MilvusAdapter(collection_name, embeddings, connection_uri='http://localhost:19530', drop_old=False, **kwargs)[source]

Bases: VectorStoreAdapter

Vector store adapter for Milvus.

Parameters:
  • collection_name (str)

  • embeddings (Embeddings)

  • connection_uri (str)

  • drop_old (bool)

  • kwargs (Any)

__init__(collection_name, embeddings, connection_uri='http://localhost:19530', drop_old=False, **kwargs)[source]

Initialises the MilvusAdapter.

Parameters:
  • collection_name (str) – Name of the Milvus collection.

  • embeddings (Embeddings) – Embeddings model to generate vector representations.

  • connection_uri (str) – Connection URI for the Milvus instance (default http://localhost:19530).

  • drop_old (bool) – Drop and recreate collection on init (default False).

  • **kwargs (Any) – Additional arguments forwarded to the Milvus vector store.

Return type:

None

upsert(document)[source]

Add or replace a document in the vector store.

Parameters:

document (Document) – The LangChain Document to upsert.

Return type:

None

upsert_batch(documents)[source]

Add or replace a list of documents in the vector store.

Parameters:

documents (list[Document]) – The list of LangChain Documents to upsert.

Return type:

None

delete(doc_id)[source]

Remove a document by its stable ID.

Parameters:

doc_id (str) – The stable ID of the document to remove.

Return type:

None

delete_batch(doc_ids)[source]

Remove a list of documents by their stable IDs in bulk.

Parameters:

doc_ids (list[str]) – The stable IDs of the documents to remove.

Return type:

None

as_retriever(*, metadata_filter=None, **kwargs)[source]

Return a LangChain BaseRetriever backed by this vector store.

Parameters:
  • metadata_filter (dict[str, Any] | None) – Optional dictionary of metadata key-values to filter by.

  • **kwargs (Any) – Options for the retriever (e.g. search_kwargs={“k”: 5}).

Returns:

A LangChain BaseRetriever.

Return type:

BaseRetriever

property store: Any

Direct access to the underlying langchain_milvus.Milvus instance.