mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-19 13:23:35 +00:00
community[patch]: Opensearch delete method added - indexing supported (#18522)
- **Description:** Added delete method for OpenSearchVectorSearch, therefore indexing supported - **Issue:** No - **Dependencies:** No - **Twitter handle:** stkbmf
This commit is contained in:
parent
687d27567d
commit
12b4a4d860
@ -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",
|
||||
|
@ -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]:
|
||||
|
@ -64,6 +64,7 @@ def test_compatible_vectorstore_documentation() -> None:
|
||||
"Milvus",
|
||||
"MomentoVectorIndex",
|
||||
"MyScale",
|
||||
"OpenSearchVectorSearch",
|
||||
"PGVector",
|
||||
"Pinecone",
|
||||
"Qdrant",
|
||||
|
Loading…
Reference in New Issue
Block a user