-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
50 lines (39 loc) · 1.75 KB
/
Copy pathconfig.py
File metadata and controls
50 lines (39 loc) · 1.75 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
Shared configuration — single source of truth for env vars and shared objects.
Both the API (chatbot_fast.py) and the worker (worker.py) import from here.
"""
import os
from dotenv import load_dotenv
from langchain_huggingface import HuggingFaceEmbeddings
from langchain_groq import ChatGroq
from qdrant_client import QdrantClient
from qdrant_client.models import VectorParams, Distance
from langchain_qdrant import QdrantVectorStore
load_dotenv()
QDRANT_COLLECTION = os.getenv("QDRANT_COLLECTION", "dealer_docs")
QDRANT_URL = os.getenv("QDRANT_URL")
QDRANT_API_KEY = os.getenv("QDRANT_API_KEY")
REDIS_URL = os.getenv("REDIS_URL", "redis://redis:6379")
DATABASE_URL = os.getenv("DATABASE_URL", "postgresql://rag:rag@postgres:5432/rag")
UPLOAD_DIR = os.getenv("UPLOAD_DIR", "/app/uploads")
MAX_RETRIES = int(os.getenv("MAX_RETRIES", "3"))
embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
llm = ChatGroq(model="llama-3.1-8b-instant", temperature=0.4)
llm_summary = ChatGroq(model="openai/gpt-oss-120b", temperature=0.3)
qdrant_client = QdrantClient(url=QDRANT_URL, api_key=QDRANT_API_KEY)
def ensure_collection():
"""Create the Qdrant collection if it doesn't exist yet."""
existing = [c.name for c in qdrant_client.get_collections().collections]
if QDRANT_COLLECTION not in existing:
qdrant_client.create_collection(
collection_name=QDRANT_COLLECTION,
vectors_config=VectorParams(size=384, distance=Distance.COSINE),
)
def get_vector_store() -> QdrantVectorStore:
"""Return a LangChain vector store bound to the shared Qdrant collection."""
ensure_collection()
return QdrantVectorStore(
client=qdrant_client,
collection_name=QDRANT_COLLECTION,
embedding=embeddings,
)