Spaces:
Sleeping
Sleeping
from functools import lru_cache | |
from pathlib import Path | |
from pydantic_settings import BaseSettings | |
class Settings(BaseSettings): | |
"""Application configuration settings""" | |
api_title: str = "NEXUS" | |
api_version: str = "0.1.0" | |
host: str = "0.0.0.0" | |
port: int = 8000 | |
chunk_size: int = 512 | |
chunk_overlap: int = 256 | |
llm_model: str = "gpt-4o" | |
rerank_model: str = "cross-encoder/ms-marco-MiniLM-L-6-v2" | |
use_colbert: bool = True | |
colbert_model: str = "answerdotai/answerai-colbert-small-v1" | |
colbert_top_k: int = 20 | |
colbert_only: bool = False | |
dense_top_k: int = 20 | |
bm25_top_k: int = 20 | |
final_top_k: int = 10 | |
bm25_weight: float = 0.55 | |
colbert_weight: float = 0.45 | |
use_reranking: bool = True | |
data_dir: str = "./data" | |
index_path: str = "./data/indices" | |
colbert_index_path: str = "./data/colbert_index" | |
uploads_dir: str = "./data/uploads" | |
openai_api_key: str | None = None | |
log_level: str = "INFO" | |
log_file: str | None = None | |
max_concurrent_index_jobs: int = 1 | |
job_timeout_minutes: int = 60 | |
class Config: | |
env_file = ".env" | |
case_sensitive = False | |
extra = "ignore" | |
def model_post_init(self, __context) -> None: | |
"""Create necessary directories after model initialization""" | |
for path in [ | |
self.data_dir, | |
self.index_path, | |
self.colbert_index_path, | |
self.uploads_dir, | |
]: | |
Path(path).mkdir(parents=True, exist_ok=True) | |
def rag_config_dict(self) -> dict: | |
"""Get RAG configuration as dictionary for compatibility with existing code""" | |
return { | |
"chunk_size": self.chunk_size, | |
"chunk_overlap": self.chunk_overlap, | |
"rerank_model": self.rerank_model, | |
"llm_model": self.llm_model, | |
"use_colbert": self.use_colbert, | |
"colbert_model": self.colbert_model, | |
"colbert_top_k": self.colbert_top_k, | |
"colbert_only": self.colbert_only, | |
"dense_top_k": self.dense_top_k, | |
"bm25_top_k": self.bm25_top_k, | |
"final_top_k": self.final_top_k, | |
"bm25_weight": self.bm25_weight, | |
"colbert_weight": self.colbert_weight, | |
"use_reranking": self.use_reranking, | |
"index_path": self.index_path, | |
"colbert_index_path": self.colbert_index_path, | |
"openai_api_key": self.openai_api_key, | |
} | |
def get_settings(): | |
return Settings() | |