diff --git a/docs/docs/modules/data_connection/indexing.ipynb b/docs/docs/modules/data_connection/indexing.ipynb index aafc86b37c1..93389a09d26 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`, `DashVector`, `DatabricksVectorSearch`, `DeepLake`, `Dingo`, `ElasticVectorSearch`, `ElasticsearchStore`, `FAISS`, `HanaDB`, `Milvus`, `MyScale`, `PGVector`, `Pinecone`, `Qdrant`, `Redis`, `Rockset`, `ScaNN`, `SupabaseVectorStore`, `SurrealDBStore`, `TimescaleVector`, `Vald`, `Vearch`, `VespaStore`, `Weaviate`, `ZepVectorStore`.\n", + "Compatible Vectorstores: `AnalyticDB`, `AstraDB`, `AwaDB`, `Bagel`, `Cassandra`, `Chroma`, `DashVector`, `DatabricksVectorSearch`, `DeepLake`, `Dingo`, `ElasticVectorSearch`, `ElasticsearchStore`, `FAISS`, `HanaDB`, `Milvus`, `MyScale`, `OpenSearchVectorSearch`, `PGVector`, `Pinecone`, `Qdrant`, `Redis`, `Rockset`, `ScaNN`, `SupabaseVectorStore`, `SurrealDBStore`, `TimescaleVector`, `Vald`, `Vearch`, `VespaStore`, `Weaviate`, `ZepVectorStore`.\n", " \n", "## Caution\n", "\n", diff --git a/libs/community/langchain_community/vectorstores/opensearch_vector_search.py b/libs/community/langchain_community/vectorstores/opensearch_vector_search.py index cf56c500e92..7ac53600d02 100644 --- a/libs/community/langchain_community/vectorstores/opensearch_vector_search.py +++ b/libs/community/langchain_community/vectorstores/opensearch_vector_search.py @@ -454,6 +454,38 @@ class OpenSearchVectorSearch(VectorStore): **kwargs, ) + def delete( + self, + ids: Optional[List[str]] = None, + refresh_indices: Optional[bool] = True, + **kwargs: Any, + ) -> Optional[bool]: + """Delete documents from the Opensearch index. + + Args: + ids: List of ids of documents to delete. + refresh_indices: Whether to refresh the index + after deleting documents. Defaults to True. + """ + bulk = _import_bulk() + + body = [] + + if ids is None: + raise ValueError("ids must be provided.") + + for _id in ids: + body.append({"_op_type": "delete", "_index": self.index_name, "_id": _id}) + + if len(body) > 0: + try: + bulk(self.client, body, refresh=refresh_indices, ignore_status=404) + return True + except Exception as e: + raise e + 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 85c5312d1f9..346952b90e6 100644 --- a/libs/community/tests/unit_tests/vectorstores/test_indexing_docs.py +++ b/libs/community/tests/unit_tests/vectorstores/test_indexing_docs.py @@ -64,6 +64,7 @@ def test_compatible_vectorstore_documentation() -> None: "Milvus", "MomentoVectorIndex", "MyScale", + "OpenSearchVectorSearch", "PGVector", "Pinecone", "Qdrant",