mirror of
https://github.com/open-webui/open-webui
synced 2025-01-30 22:39:03 +00:00
enh: vector db delete filter support
This commit is contained in:
parent
351b1dbf31
commit
325ca98773
@ -111,11 +111,19 @@ class ChromaClient:
|
|||||||
ids=ids, documents=documents, embeddings=embeddings, metadatas=metadatas
|
ids=ids, documents=documents, embeddings=embeddings, metadatas=metadatas
|
||||||
)
|
)
|
||||||
|
|
||||||
def delete(self, collection_name: str, ids: list[str]):
|
def delete(
|
||||||
|
self,
|
||||||
|
collection_name: str,
|
||||||
|
ids: Optional[list[str]] = None,
|
||||||
|
filter: Optional[dict] = None,
|
||||||
|
):
|
||||||
# Delete the items from the collection based on the ids.
|
# Delete the items from the collection based on the ids.
|
||||||
collection = self.client.get_collection(name=collection_name)
|
collection = self.client.get_collection(name=collection_name)
|
||||||
if collection:
|
if collection:
|
||||||
|
if ids:
|
||||||
collection.delete(ids=ids)
|
collection.delete(ids=ids)
|
||||||
|
elif filter:
|
||||||
|
collection.delete(where=filter)
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
# Resets the database. This will delete all collections and item entries.
|
# Resets the database. This will delete all collections and item entries.
|
||||||
|
@ -187,13 +187,32 @@ class MilvusClient:
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
def delete(self, collection_name: str, ids: list[str]):
|
def delete(
|
||||||
|
self,
|
||||||
|
collection_name: str,
|
||||||
|
ids: Optional[list[str]] = None,
|
||||||
|
filter: Optional[dict] = None,
|
||||||
|
):
|
||||||
# Delete the items from the collection based on the ids.
|
# Delete the items from the collection based on the ids.
|
||||||
|
|
||||||
|
if ids:
|
||||||
return self.client.delete(
|
return self.client.delete(
|
||||||
collection_name=f"{self.collection_prefix}_{collection_name}",
|
collection_name=f"{self.collection_prefix}_{collection_name}",
|
||||||
ids=ids,
|
ids=ids,
|
||||||
)
|
)
|
||||||
|
elif filter:
|
||||||
|
# Convert the filter dictionary to a string using JSON_CONTAINS.
|
||||||
|
filter_string = " && ".join(
|
||||||
|
[
|
||||||
|
f"JSON_CONTAINS(metadata[{key}], '{[value] if isinstance(value, str) else value}')"
|
||||||
|
for key, value in filter.items()
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
return self.client.delete(
|
||||||
|
collection_name=f"{self.collection_prefix}_{collection_name}",
|
||||||
|
filter=filter_string,
|
||||||
|
)
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
# Resets the database. This will delete all collections and item entries.
|
# Resets the database. This will delete all collections and item entries.
|
||||||
|
Loading…
Reference in New Issue
Block a user