From 15d96b1f2a35123682b3dd6b264d75e6c8b3fed6 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Mon, 29 Jun 2026 09:15:05 +0200 Subject: [PATCH] fix: chroma has_collection always returns False (name vs Collection) (#25780) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit has_collection did `collection_name in self.client.list_collections()`, but chromadb's list_collections() returns Collection objects (1.x), not name strings — so the membership test is always False, even when the collection exists. Compare against the collection names instead (with a hasattr guard tolerating versions that yield plain names). Found via the dependency-contract test suite (unit/deps/test_chromadb.py). --- backend/open_webui/retrieval/vector/dbs/chroma.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/retrieval/vector/dbs/chroma.py b/backend/open_webui/retrieval/vector/dbs/chroma.py index cd0a59eeaf..408a02111f 100755 --- a/backend/open_webui/retrieval/vector/dbs/chroma.py +++ b/backend/open_webui/retrieval/vector/dbs/chroma.py @@ -57,7 +57,11 @@ class ChromaClient(VectorDBBase): def has_collection(self, collection_name: str) -> bool: # Check if the collection exists based on the collection name. - collection_names = self.client.list_collections() + # chromadb's list_collections() returns Collection objects (1.x), so a + # bare `name in collections` membership test is always False — compare + # against the names. (hasattr guard tolerates versions that yield names.) + collections = self.client.list_collections() + collection_names = [c.name if hasattr(c, 'name') else c for c in collections] return collection_name in collection_names def delete_collection(self, collection_name: str):