Spaces:
Sleeping
Sleeping
File size: 1,888 Bytes
2e82da7 | 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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | import qdrant_client
from qdrant_client.http import models
from qdrant_client.http.models import Distance, VectorParams
import os
from dotenv import load_dotenv
load_dotenv()
class QdrantSetup:
def __init__(self, host=None, port=None, api_key=None, https=True):
"""
Initialize Qdrant client - supports both local and cloud instances
"""
cloud_url = os.getenv("QDRANT_URL")
cloud_api_key = os.getenv("QDRANT_API_KEY")
if cloud_url:
self.client = qdrant_client.QdrantClient(
url=cloud_url,
api_key=cloud_api_key,
https=https
)
else:
host = host or os.getenv("QDRANT_HOST", "localhost")
port = port or int(os.getenv("QDRANT_PORT", 6333))
self.client = qdrant_client.QdrantClient(
host=host,
port=port
)
self.collection_name = "hindi_poems_stories"
def create_collection(self, vector_size=384):
"""Create a collection in Qdrant for storing text embeddings"""
collections = self.client.get_collections()
collection_names = [col.name for col in collections.collections]
if self.collection_name in collection_names:
print(f"Collection '{self.collection_name}' already exists.")
return
self.client.create_collection(
collection_name=self.collection_name,
vectors_config=VectorParams(size=vector_size, distance=Distance.COSINE),
)
print(f"Collection '{self.collection_name}' created successfully.")
def get_client(self):
return self.client
def get_collection_name(self):
return self.collection_name
if __name__ == "__main__":
qdrant_setup = QdrantSetup()
qdrant_setup.create_collection()
print("Qdrant setup completed!")
|