mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-20 13:54:48 +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",
|
" * document addition by id (`add_documents` method with `ids` argument)\n",
|
||||||
" * delete by id (`delete` method with `ids` argument)\n",
|
" * delete by id (`delete` method with `ids` argument)\n",
|
||||||
"\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",
|
" \n",
|
||||||
"## Caution\n",
|
"## Caution\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
@ -454,6 +454,38 @@ class OpenSearchVectorSearch(VectorStore):
|
|||||||
**kwargs,
|
**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(
|
def similarity_search(
|
||||||
self, query: str, k: int = 4, **kwargs: Any
|
self, query: str, k: int = 4, **kwargs: Any
|
||||||
) -> List[Document]:
|
) -> List[Document]:
|
||||||
|
@ -64,6 +64,7 @@ def test_compatible_vectorstore_documentation() -> None:
|
|||||||
"Milvus",
|
"Milvus",
|
||||||
"MomentoVectorIndex",
|
"MomentoVectorIndex",
|
||||||
"MyScale",
|
"MyScale",
|
||||||
|
"OpenSearchVectorSearch",
|
||||||
"PGVector",
|
"PGVector",
|
||||||
"Pinecone",
|
"Pinecone",
|
||||||
"Qdrant",
|
"Qdrant",
|
||||||
|
Loading…
Reference in New Issue
Block a user