refac
This commit is contained in:
1 parent
7e31f64bc8
commit
48ee357156
1 file changed
+6
-7
@@ -3,6 +3,7 @@ from typing import Optional
|
|||||||
|
|
||||||
import chromadb
|
import chromadb
|
||||||
from chromadb import Settings
|
from chromadb import Settings
|
||||||
|
from chromadb.errors import NotFoundError
|
||||||
from chromadb.utils.batch_utils import create_batches
|
from chromadb.utils.batch_utils import create_batches
|
||||||
from open_webui.config import (
|
from open_webui.config import (
|
||||||
CHROMA_CLIENT_AUTH_CREDENTIALS,
|
CHROMA_CLIENT_AUTH_CREDENTIALS,
|
||||||
@@ -56,13 +57,11 @@ class ChromaClient(VectorDBBase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def has_collection(self, collection_name: str) -> bool:
|
def has_collection(self, collection_name: str) -> bool:
|
||||||
# Check if the collection exists based on the collection name.
|
try:
|
||||||
# chromadb's list_collections() returns Collection objects (1.x), so a
|
self.client.get_collection(name=collection_name)
|
||||||
# bare `name in collections` membership test is always False — compare
|
return True
|
||||||
# against the names. (hasattr guard tolerates versions that yield names.)
|
except NotFoundError:
|
||||||
collections = self.client.list_collections()
|
return False
|
||||||
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):
|
def delete_collection(self, collection_name: str):
|
||||||
# Delete the collection based on the collection name.
|
# Delete the collection based on the collection name.
|
||||||
|
|||||||
Reference in new issue
Block a user