langchain-ai/langchain · error · NotImplementedError
`add_documents` and `add_texts` has not been implemented for
Error message
`add_documents` and `add_texts` has not been implemented for {self.__class__.__name__} What it means
Raised by the base `VectorStore.add_documents` when the subclass implements neither `add_texts` nor `add_documents`/`upsert` override, meaning the store has no ingestion path at all. The message names both methods because the shim tries `add_texts` as the fallback primitive before giving up.
Source
Thrown at libs/core/langchain_core/vectorstores/base.py:263
List of IDs of the added texts.
"""
if type(self).add_texts != VectorStore.add_texts:
if "ids" not in kwargs:
ids = [doc.id for doc in documents]
# If there's at least one valid ID, we'll assume that IDs
# should be used.
if any(ids):
kwargs["ids"] = ids
texts = [doc.page_content for doc in documents]
metadatas = [doc.metadata for doc in documents]
return self.add_texts(texts, metadatas, **kwargs)
msg = (
f"`add_documents` and `add_texts` has not been implemented "
f"for {self.__class__.__name__} "
)
raise NotImplementedError(msg)
async def aadd_documents(
self, documents: list[Document], **kwargs: Any
) -> list[str]:
"""Async run more documents through the embeddings and add to the `VectorStore`.
Args:
documents: Documents to add to the `VectorStore`.
**kwargs: Additional keyword arguments.
Returns:
List of IDs of the added texts.
"""
# If the async method has been overridden, we'll use that.
if type(self).aadd_texts != VectorStore.aadd_texts:
if "ids" not in kwargs:
ids = [doc.id for doc in documents]
View on GitHub (pinned to e32fa9a52e)
Solutions
- Implement `add_texts` (preferred minimal primitive) or `add_documents`/`upsert` in the subclass.
- If the store is populated externally (e.g. by a separate indexer), remove ingestion calls from your pipeline and load documents out-of-band.
- Gate generic pipelines: only call `add_documents` when `type(store).add_texts is not VectorStore.add_texts`.
Example fix
# before
class ReadOnlyStore(VectorStore):
def similarity_search(self, query, k=4, **kwargs):
return self._search(query, k)
ReadOnlyStore(...).add_documents(docs) # NotImplementedError
# after
class WritableStore(ReadOnlyStore):
def add_texts(self, texts, metadatas=None, **kwargs):
return self._backend.bulk_insert(texts, metadatas or [{}] * len(texts)) Defensive patterns
Strategy: type-guard
Validate before calling
from langchain_core.vectorstores import VectorStore
def ingestion_ready(store: VectorStore) -> bool:
return (
type(store).add_texts is not VectorStore.add_texts
or type(store).add_documents is not VectorStore.add_documents
)
if ingestion_ready(store):
ids = store.add_documents(docs)
else:
raise RuntimeError(f"{type(store).__name__} is read-only; load documents externally") Type guard
from langchain_core.vectorstores import VectorStore
def can_add_documents(store: VectorStore) -> bool:
"""True if any ingestion path is implemented."""
return (
type(store).add_texts is not VectorStore.add_texts
or type(store).add_documents is not VectorStore.add_documents
) Try / catch
try:
ids = store.add_documents(docs)
except NotImplementedError as e:
raise RuntimeError(
f"Store {type(store).__name__} cannot ingest; populate it via its native loader"
) from e Prevention
- Feature-detect ingestion before calling `from_documents` helpers.
- For externally-populated indexes, wrap them in a read-only façade that hides ingestion APIs.
- When subclassing, implementing `add_texts` alone satisfies both `add_texts` and `add_documents`.
When it happens
Trigger: Calling `add_documents(docs)` or `VectorStore.from_documents(docs, store)` on a custom subclass that only implements search/read methods; stores that subclass `VectorStore` purely for interface compliance.
Common situations: Read-only or externally-populated index wrappers; prototype subclasses where only `similarity_search` was written; helper utilities that blindly call `from_documents` on any `VectorStore` instance.
Related errors
- `add_texts` has not been implemented for {self.__class__.__n
- The number of metadatas must match the number of texts.Got {
- delete method must be implemented by subclass.
- {self.__class__.__name__} does not yet support get_by_ids.
- The delete operation to VectorStore failed.
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/0ac0204ff9d1d376.
Report an issue: GitHub.