{"record":{"id":"ca570e00b67cc076","repo":"langchain-ai/langchain","slug":"vectorstore-should-be-either-a-vectorstore-or-a-do","errorCode":null,"errorMessage":"Vectorstore should be either a VectorStore or a DocumentIndex. Got {type(vector_store)}.","messagePattern":"Vectorstore should be either a VectorStore or a DocumentIndex\\. Got (.+?)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/indexing/api.py","lineNumber":277,"sourceCode":"        TypeError: If the `vector_store` is neither a `VectorStore` nor a\n            `DocumentIndex`.\n    \"\"\"\n    if isinstance(vector_store, VectorStore):\n        delete_ok = vector_store.delete(ids)\n        if delete_ok is not None and delete_ok is False:\n            msg = \"The delete operation to VectorStore failed.\"\n            raise IndexingException(msg)\n    elif isinstance(vector_store, DocumentIndex):\n        delete_response = vector_store.delete(ids)\n        if \"num_failed\" in delete_response and delete_response[\"num_failed\"] > 0:\n            msg = \"The delete operation to DocumentIndex failed.\"\n            raise IndexingException(msg)\n    else:\n        msg = (  # type: ignore[unreachable]\n            f\"Vectorstore should be either a VectorStore or a DocumentIndex. \"\n            f\"Got {type(vector_store)}.\"\n        )\n        raise TypeError(msg)\n\n\n# PUBLIC API\n\n\nclass IndexingResult(TypedDict):\n    \"\"\"Return a detailed a breakdown of the result of the indexing operation.\"\"\"\n\n    num_added: int\n    \"\"\"Number of added documents.\"\"\"\n    num_updated: int\n    \"\"\"Number of updated documents because they were not up to date.\"\"\"\n    num_deleted: int\n    \"\"\"Number of deleted documents.\"\"\"\n    num_skipped: int\n    \"\"\"Number of skipped documents because they were already up to date.\"\"\"\n\n","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/indexing/api.py#L259-L295","documentation":"Raised by `_delete` in `langchain_core.indexing.api` when the object passed as the indexing destination is neither a `VectorStore` nor a `DocumentIndex` instance. The indexer needs one of those two interfaces to write and delete documents; anything else (a retriever, a plain object, a Mock) is a `TypeError`. Marked unreachable by type checkers because the signature restricts the type, but duck-typed callers can hit it.","triggerScenarios":"Calling `index(retriever, docs, rm)` (an arbitrary retriever is not a VectorStore); passing a wrapper/proxy object that does not subclass VectorStore or register as DocumentIndex; passing a Mock in tests.","commonSituations":"Assuming any retriever-like object works with the indexing API; wrapping a vector store in a custom class without inheriting from `VectorStore`; test doubles replacing the store.","solutions":["Pass the actual `VectorStore` instance (e.g. the `Chroma`/`FAISS`/`PGVector` object) to `index()`.","If you have a custom store, subclass `langchain_core.vectorstores.base.VectorStore` and implement `add_documents`/`delete` (plus similarity APIs as applicable).","For docstore-style targets, implement/extend the `DocumentIndex` interface instead."],"exampleFix":"# before\nindex(my_retriever, docs, record_manager)  # retriever is not a VectorStore\n\n# after\nindex(my_retriever.vectorstore, docs, record_manager)","handlingStrategy":"type-guard","validationCode":"from langchain_core.vectorstores import VectorStore\nfrom langchain_core.document_loaders import DocumentIndex  # or langchain_core.indexing\n\nif not isinstance(destination, (VectorStore, DocumentIndex)):\n    raise TypeError(\"index() requires a VectorStore or DocumentIndex\")","typeGuard":"def is_indexing_target(obj) -> bool:\n    from langchain_core.vectorstores import VectorStore\n    return isinstance(obj, VectorStore) or getattr(obj, \"delete\", None) is not None and hasattr(obj, \"add_documents\")","tryCatchPattern":null,"preventionTips":["Type your pipeline functions as `vector_store: VectorStore` so mypy catches this before runtime.","Do not pass retrievers or raw SDK clients to index()."],"tags":["indexing","type-error","vector-store"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}