From bdd236fa3aa1efc038d2992a5a0f9a05e9a156ea Mon Sep 17 00:00:00 2001 From: Jonathan Flower Date: Sat, 22 Mar 2025 09:59:06 -0400 Subject: [PATCH] improved error handling for deleting collections that do not exist in chromadb --- .../open_webui/retrieval/vector/dbs/chroma.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/backend/open_webui/retrieval/vector/dbs/chroma.py b/backend/open_webui/retrieval/vector/dbs/chroma.py index 006ee2076..f15702cf1 100755 --- a/backend/open_webui/retrieval/vector/dbs/chroma.py +++ b/backend/open_webui/retrieval/vector/dbs/chroma.py @@ -166,12 +166,17 @@ class ChromaClient: filter: Optional[dict] = None, ): # Delete the items from the collection based on the ids. - collection = self.client.get_collection(name=collection_name) - if collection: - if ids: - collection.delete(ids=ids) - elif filter: - collection.delete(where=filter) + try: + collection = self.client.get_collection(name=collection_name) + if collection: + if ids: + collection.delete(ids=ids) + elif filter: + collection.delete(where=filter) + except Exception as e: + # If collection doesn't exist, that's fine - nothing to delete + log.debug(f"Attempted to delete from non-existent collection {collection_name}. Ignoring.") + pass def reset(self): # Resets the database. This will delete all collections and item entries.