Spaces:
Runtime error
Runtime error
File size: 1,446 Bytes
0457256 |
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 |
import uuid
from langchain_community.vectorstores import Qdrant
from qdrant_client import models
from utils import setup_qdrant_client,setup_openai_embeddings
def embed_documents_into_qdrant(documents, api_key, qdrant_url, qdrant_api_key, collection_name="Lex-v1"):
"""Embed documents into Qdrant."""
embeddings_model = setup_openai_embeddings(api_key)
client = setup_qdrant_client(qdrant_url, qdrant_api_key)
qdrant = Qdrant(client=client, collection_name=collection_name, embeddings=embeddings_model)
try:
qdrant.add_documents(documents)
except Exception as e:
print("Failed to embed documents:", e)
def embed_documents_with_unique_collection(documents, api_key, qdrant_url, qdrant_api_key, collection_name=None):
"""Embed documents into a unique Qdrant collection."""
if not collection_name:
collection_name = f"session-{uuid.uuid4()}"
client = setup_qdrant_client(qdrant_url, qdrant_api_key)
client.create_collection(
collection_name=collection_name,
vectors_config=models.VectorParams(size=1536, distance=models.Distance.COSINE)
)
embeddings_model = setup_openai_embeddings(api_key)
qdrant = Qdrant(client=client, collection_name=collection_name, embeddings=embeddings_model)
try:
qdrant.add_documents(documents)
except Exception as e:
print("Failed to embed documents:", e)
return collection_name |