mirror of
https://github.com/hwchase17/langchain.git
synced 2025-05-28 10:39:23 +00:00
Update docs to specify Indexing-API-compatible vectorstores (#11581)
**Description:** Update Indexing API docs to specify vectorstores that are compatible with the Indexing API. I add a unit test to remind developers to update the documentation whenever they add or change a vectorstore in a way that affects compatibility. For the unit test I repurposed existing code from [here](https://github.com/langchain-ai/langchain/blob/v0.0.311/libs/langchain/langchain/indexes/_api.py#L245-L257). This is my first PR to an open source project. This is a trivially simple PR whose main purpose is to make me more comfortable submitting Langchain PRs. If this PR goes through I plan to submit PRs with more substantive changes in the near future. **Issue:** Resolves [10482](https://github.com/langchain-ai/langchain/discussions/10482). **Dependencies:** No new dependencies. **Twitter handle:** None.
This commit is contained in:
parent
6402c33299
commit
9d1867c77f
@ -59,6 +59,8 @@
|
||||
"2. Only works with LangChain `vectorstore`'s that support:\n",
|
||||
" * document addition by id (`add_documents` method with `ids` argument)\n",
|
||||
" * delete by id (`delete` method with)\n",
|
||||
"\n",
|
||||
"Compatible Vectorstores: `AnalyticDB`, `AwaDB`, `Bagel`, `Cassandra`, `Chroma`, `DashVector`, `DeepLake`, `Dingo`, `ElasticVectorSearch`, `ElasticsearchStore`, `FAISS`, `PGVector`, `Pinecone`, `Qdrant`, `Redis`, `ScaNN`, `SupabaseVectorStore`, `TimescaleVector`, `Vald`, `Vearch`, `VespaStore`, `Weaviate`, `ZepVectorStore`.\n",
|
||||
" \n",
|
||||
"## Caution\n",
|
||||
"\n",
|
||||
|
@ -15,6 +15,7 @@ from unittest.mock import patch
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
|
||||
import langchain.vectorstores
|
||||
from langchain.document_loaders.base import BaseLoader
|
||||
from langchain.embeddings.base import Embeddings
|
||||
from langchain.indexes import aindex, index
|
||||
@ -1078,3 +1079,76 @@ async def test_abatch() -> None:
|
||||
batches = _abatch(2, _to_async_iter(range(5)))
|
||||
assert isinstance(batches, AsyncIterator)
|
||||
assert [batch async for batch in batches] == [[0, 1], [2, 3], [4]]
|
||||
|
||||
|
||||
def test_compatible_vectorstore_documentation() -> None:
|
||||
"""Test which vectorstores are compatible with the indexing API.
|
||||
|
||||
This serves as a reminder to update the documentation in [1]
|
||||
that specifies which vectorstores are compatible with the
|
||||
indexing API.
|
||||
|
||||
Ideally if a developer adds a new vectorstore or modifies
|
||||
an existing one in such a way that affects its compatibility
|
||||
with the Indexing API, he/she will see this failed test
|
||||
case and 1) update docs in [1] and 2) update the `documented`
|
||||
dict in this test case.
|
||||
|
||||
[1] langchain/docs/docs_skeleton/docs/modules/data_connection/indexing.ipynb
|
||||
"""
|
||||
|
||||
# Check if a vectorstore is compatible with the indexing API
|
||||
def check_compatibility(vector_store: VectorStore) -> bool:
|
||||
"""Check if a vectorstore is compatible with the indexing API."""
|
||||
methods = ["delete", "add_documents"]
|
||||
for method in methods:
|
||||
if not hasattr(vector_store, method):
|
||||
return False
|
||||
# Checking if the vectorstore has overridden the default delete method
|
||||
# implementation which just raises a NotImplementedError
|
||||
if getattr(vector_store, "delete") == VectorStore.delete:
|
||||
return False
|
||||
return True
|
||||
|
||||
# Check all vector store classes for compatibility
|
||||
compatible = set()
|
||||
for class_name in langchain.vectorstores.__all__:
|
||||
# Get the definition of the class
|
||||
cls = getattr(langchain.vectorstores, class_name)
|
||||
|
||||
# If the class corresponds to a vectorstore, check its compatibility
|
||||
if issubclass(cls, VectorStore):
|
||||
is_compatible = check_compatibility(cls)
|
||||
if is_compatible:
|
||||
compatible.add(class_name)
|
||||
|
||||
# These are mentioned in the indexing.ipynb documentation
|
||||
documented = {
|
||||
"AnalyticDB",
|
||||
"AzureCosmosDBVectorSearch",
|
||||
"AwaDB",
|
||||
"Bagel",
|
||||
"Cassandra",
|
||||
"Chroma",
|
||||
"DashVector",
|
||||
"DeepLake",
|
||||
"Dingo",
|
||||
"ElasticVectorSearch",
|
||||
"ElasticsearchStore",
|
||||
"FAISS",
|
||||
"MomentoVectorIndex",
|
||||
"PGVector",
|
||||
"Pinecone",
|
||||
"Qdrant",
|
||||
"Redis",
|
||||
"ScaNN",
|
||||
"SemaDB",
|
||||
"SupabaseVectorStore",
|
||||
"TimescaleVector",
|
||||
"Vald",
|
||||
"Vearch",
|
||||
"VespaStore",
|
||||
"Weaviate",
|
||||
"ZepVectorStore",
|
||||
}
|
||||
assert compatible == documented
|
||||
|
Loading…
Reference in New Issue
Block a user