Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Abstract collection existence check into a utility function #1814

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions camel/storages/vectordb_storages/qdrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
)
from camel.types import VectorDistance
from camel.utils import dependencies_required
from .utils import collection_exists

_qdrant_local_client_map: Dict[str, Tuple[Any, int]] = {}
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -218,11 +219,8 @@ def _delete_collection(
)

def _collection_exists(self, collection_name: str) -> bool:
r"""Returns wether the collection exists in the database"""
for c in self._client.get_collections().collections:
if collection_name == c.name:
return True
return False
"""Returns whether the collection exists in the database."""
return collection_exists(self._client, collection_name)

def _generate_collection_name(self) -> str:
r"""Generates a collection name if user doesn't provide"""
Expand Down
6 changes: 6 additions & 0 deletions camel/storages/vectordb_storages/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def collection_exists(client, collection_name: str) -> bool:
"""Check if a collection exists in the database."""
for c in client.get_collections().collections:
if collection_name == c.name:
return True
return False
Loading