mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-17 07:26:16 +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:
@@ -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",
|
||||
|
Reference in New Issue
Block a user