-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqdrant_setup.py
More file actions
36 lines (27 loc) · 1.08 KB
/
qdrant_setup.py
File metadata and controls
36 lines (27 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
from qdrant_client import QdrantClient
from dotenv import load_dotenv
load_dotenv()
def get_qdrant_client():
url = os.getenv("QDRANT_URL")
api_key = os.getenv("QDRANT_API_KEY")
if not url or not api_key:
raise ValueError("QDRANT_URL and QDRANT_API_KEY must be set in .env file")
return QdrantClient(url=url, api_key=api_key, timeout=60.0)
def check_collection_exists(client: QdrantClient, collection_name: str) -> bool:
try:
collections = client.get_collections()
collection_names = [col.name for col in collections.collections]
return collection_name in collection_names
except Exception as e:
print(f" Error checking collections: {e}")
return False
def check_collection_has_data(client: QdrantClient, collection_name: str) -> int:
try:
if not check_collection_exists(client, collection_name):
return 0
count = client.count(collection_name=collection_name)
return count.count
except Exception as e:
print(f" Error checking collection data: {e}")
return 0