-
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.98 KB
/
config.py
File metadata and controls
50 lines (39 loc) · 1.98 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
import os
from dotenv import load_dotenv
# === Load environment variables from .env file ===
load_dotenv()
# === API Keys ===
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
BEARER_TOKEN = os.getenv("BEARER_TOKEN")
if not GROQ_API_KEY or not BEARER_TOKEN:
raise EnvironmentError("GROQ_API_KEY and BEARER_TOKEN must be set in .env file")
# === LLM Model ===
LLM_MODEL = os.getenv("LLM_MODEL", "llama3-8b-8192")
# === PDF Folder Configuration ===
ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
PDF_FOLDER = os.path.join(ROOT_DIR, os.getenv("PDF_FOLDER", "pdfs"))
# === Chunking Config (optimized for token-based chunking) ===
CHUNK_SIZE = int(os.getenv("CHUNK_SIZE", 512)) # Max tokens per chunk
CHUNK_OVERLAP = int(os.getenv("CHUNK_OVERLAP", 50)) # Overlap in tokens
MIN_CHUNK_LENGTH = int(os.getenv("MIN_CHUNK_LENGTH", 10)) # Min tokens
TOP_K_CHUNKS = int(os.getenv("TOP_K_CHUNKS", 5)) # Increased for better context
# === Embedding Vector Dimension (must match your embedding model and pgvector column) ===
EMBEDDING_DIM = int(os.getenv("EMBEDDING_DIM", 384))
# === PostgreSQL DB Config ===
DB_NAME = os.getenv("DB_NAME")
DB_USER = os.getenv("DB_USER")
DB_PASSWORD = os.getenv("DB_PASSWORD")
DB_HOST = os.getenv("DB_HOST", "localhost")
DB_PORT = os.getenv("DB_PORT", "5432")
DB_TABLE = os.getenv("DB_TABLE", "document_chunks")
# === Performance Optimization Config ===
BATCH_SIZE = int(os.getenv("BATCH_SIZE", 32)) # Batch size for embedding generation
CACHE_SIZE = int(os.getenv("CACHE_SIZE", 5000)) # LRU cache size for embeddings
USE_GPU = os.getenv("USE_GPU", "true").lower() == "true" # Enable GPU acceleration
USE_FAISS = os.getenv("USE_FAISS", "false").lower() == "true" # Use FAISS instead of pgvector
# === Connection Pool Config ===
DB_POOL_MIN = int(os.getenv("DB_POOL_MIN", 2))
DB_POOL_MAX = int(os.getenv("DB_POOL_MAX", 10))
# Ensure all critical DB fields are set
if not all([DB_NAME, DB_USER, DB_PASSWORD]):
raise EnvironmentError("Database configuration incomplete in .env file")