Skip to content

The agent engineering platform.

community[patch]: add delete() method to AzureSearch vector store (#21127)

MacanPN0f7f44860341
diff --git a/docs/docs/modules/data_connection/indexing.ipynb b/docs/docs/modules/data_connection/indexing.ipynb
index 0428eec010..c8d8b2fd1e 100644
--- a/docs/docs/modules/data_connection/indexing.ipynb
+++ b/docs/docs/modules/data_connection/indexing.ipynb
@@ -60,7 +60,7 @@
" * document addition by id (`add_documents` method with `ids` argument)\n",
" * delete by id (`delete` method with `ids` argument)\n",
"\n",
- "Compatible Vectorstores: `AnalyticDB`, `AstraDB`, `AwaDB`, `Bagel`, `Cassandra`, `Chroma`, `CouchbaseVectorStore`, `DashVector`, `DatabricksVectorSearch`, `DeepLake`, `Dingo`, `ElasticVectorSearch`, `ElasticsearchStore`, `FAISS`, `HanaDB`, `LanceDB`, `Milvus`, `MyScale`, `OpenSearchVectorSearch`, `PGVector`, `Pinecone`, `Qdrant`, `Redis`, `Rockset`, `ScaNN`, `SupabaseVectorStore`, `SurrealDBStore`, `TimescaleVector`, `UpstashVectorStore`, `Vald`, `VDMS`, `Vearch`, `VespaStore`, `Weaviate`, `ZepVectorStore`, `TencentVectorDB`, `OpenSearchVectorSearch`.\n",
+ "Compatible Vectorstores: `AnalyticDB`, `AstraDB`, `AzureCosmosDBVectorSearch`, `AzureSearch`, `AwaDB`, `Bagel`, `Cassandra`, `Chroma`, `CouchbaseVectorStore`, `DashVector`, `DatabricksVectorSearch`, `DeepLake`, `Dingo`, `ElasticVectorSearch`, `ElasticsearchStore`, `FAISS`, `HanaDB`, `LanceDB`, `Milvus`, `MyScale`, `OpenSearchVectorSearch`, `PGVector`, `Pinecone`, `Qdrant`, `Redis`, `Rockset`, `ScaNN`, `SupabaseVectorStore`, `SurrealDBStore`, `TimescaleVector`, `UpstashVectorStore`, `Vald`, `VDMS`, `Vearch`, `VespaStore`, `Weaviate`, `ZepVectorStore`, `TencentVectorDB`, `OpenSearchVectorSearch`.\n",
" \n",
"## Caution\n",
"\n",
diff --git a/libs/community/langchain_community/vectorstores/azuresearch.py b/libs/community/langchain_community/vectorstores/azuresearch.py
index 5d154fa210..3e00166278 100644
--- a/libs/community/langchain_community/vectorstores/azuresearch.py
+++ b/libs/community/langchain_community/vectorstores/azuresearch.py
@@ -377,6 +377,22 @@ class AzureSearch(VectorStore):
else:
raise Exception(response)
+ def delete(self, ids: Optional[List[str]] = None, **kwargs: Any) -> bool:
+ """Delete by vector ID.
+
+ Args:
+ ids: List of ids to delete.
+
+ Returns:
+ bool: True if deletion is successful,
+ False otherwise.
+ """
+ if ids:
+ res = self.client.delete_documents([{"id": i} for i in ids])
+ return len(res) > 0
+ else:
+ return False
+
def similarity_search(
self, query: str, k: int = 4, **kwargs: Any
) -> List[Document]:
diff --git a/libs/community/tests/unit_tests/vectorstores/test_indexing_docs.py b/libs/community/tests/unit_tests/vectorstores/test_indexing_docs.py
index be09399262..f85f3d345c 100644
--- a/libs/community/tests/unit_tests/vectorstores/test_indexing_docs.py
+++ b/libs/community/tests/unit_tests/vectorstores/test_indexing_docs.py
@@ -16,7 +16,7 @@ def test_compatible_vectorstore_documentation() -> None:
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
+ [1] langchain/docs/docs/modules/data_connection/indexing.ipynb
"""
# Check if a vectorstore is compatible with the indexing API
@@ -49,6 +49,7 @@ def test_compatible_vectorstore_documentation() -> None:
"AnalyticDB",
"AstraDB",
"AzureCosmosDBVectorSearch",
+ "AzureSearch",
"AwaDB",
"Bagel",
"BESVectorStore",