File size: 1,986 Bytes
e7a3876
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
56
57
58
59
60
61
"""

Loads config.yaml and .env into a single typed config object.

Everything in the codebase imports from here — no hardcoded values elsewhere.

"""

import os
from pathlib import Path
import yaml
from dotenv import load_dotenv

load_dotenv()

_CONFIG_PATH = Path(__file__).parent.parent.parent / "configs" / "config.yaml"


def _load_yaml() -> dict:
    with open(_CONFIG_PATH, "r") as f:
        return yaml.safe_load(f)


class Config:
    """Single source of truth for all runtime settings."""

    def __init__(self):
        cfg = _load_yaml()

        # Ingestion
        self.chunk_size: int = cfg["ingestion"]["chunk_size"]
        self.chunk_overlap: int = cfg["ingestion"]["chunk_overlap"]

        # Retrieval
        self.embedding_model: str = cfg["retrieval"]["embedding_model"]
        self.top_k: int = cfg["retrieval"]["top_k"]
        self.collection_name: str = cfg["retrieval"]["collection_name"]
        self.chroma_persist_dir: str = cfg["retrieval"]["chroma_persist_dir"]

        # Generation
        self.llm_backend: str = cfg["generation"]["backend"]
        self.groq_model: str = cfg["generation"]["groq_model"]
        self.max_new_tokens: int = cfg["generation"]["max_new_tokens"]
        self.temperature: float = cfg["generation"]["temperature"]
        self.groq_model: str = cfg["generation"]["groq_model"]

        # Secrets from .env (never from yaml)
        self.hf_api_token: str = os.getenv("HF_API_TOKEN", "")
        self.ollama_base_url: str = os.getenv("OLLAMA_BASE_URL", "http://localhost:11434")

        # Evaluation
        self.faithfulness_threshold: float = cfg["evaluation"]["faithfulness_threshold"]

    def __repr__(self):
        return (
            f"Config(backend={self.llm_backend}, "
            f"embedding={self.embedding_model}, "
            f"chunk_size={self.chunk_size})"
        )


# Module-level singleton — import this everywhere
config = Config()