File size: 1,363 Bytes
319392e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fb67cc1
319392e
 
 
 
 
 
 
 
 
 
 
 
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
from langchain_openai import OpenAIEmbeddings, ChatOpenAI
from qdrant_client import QdrantClient


def setup_openai_embeddings(api_key):
    """Set up OpenAI embeddings."""
    return OpenAIEmbeddings(model='text-embedding-3-small', openai_api_key=api_key)


def setup_qdrant_client(url, api_key):
    """Set up Qdrant client."""
    return QdrantClient(location=url, api_key=api_key)

def format_document_metadata(docs):
    """Format metadata for each document."""
    formatted_docs = []
    for doc in docs:
        metadata_str = ', '.join(f"{key}: {value}" for key, value in doc.metadata.items())
        doc_str = f"{doc.page_content}\nMetadata: {metadata_str}"
        formatted_docs.append(doc_str)
    return "\n\n".join(formatted_docs)

def openai_llm(api_key: str):
    """Get a configured OpenAI language model."""
    return ChatOpenAI(model_name="gpt-4o", temperature=0, openai_api_key=api_key)

def delete_collection(collection_name, qdrant_url, qdrant_api_key):
    """Delete a Qdrant collection."""
    client = setup_qdrant_client(qdrant_url, qdrant_api_key)
    try:
        client.delete_collection(collection_name=collection_name)
    except Exception as e:
        print("Failed to delete collection:", e)

def is_document_embedded(filename):
    """Check if a document is already embedded. Actual implementation needed."""
    return False