"""Runtime configuration for the RAG app. Reads everything from environment variables (optionally loaded from a local `.env` file) so the exact same code runs unmodified locally and on a Hugging Face Space -- Space secrets are injected as environment variables. Index artifacts (FAISS/BM25/chunks) are resolved "local cache first, Hugging Face Hub fallback" by `src/index_registry.py`, so no separate local/HF mode flag is needed for that either. """ import os from pathlib import Path try: from dotenv import load_dotenv load_dotenv() except ImportError: pass PROJECT_ROOT = Path(os.environ.get("RAG_PROJECT_ROOT", Path(__file__).resolve().parents[1])) DATA_DIR = PROJECT_ROOT / "data" CACHE_DIR = DATA_DIR / "cache" INDICES_DIR = CACHE_DIR / "indices" RESULTS_DIR = PROJECT_ROOT / "results" CONFIGS_DIR = PROJECT_ROOT / "configs" # Local cache for benchmark eval results / query-transform results (NB6-style cache). APP_CACHE_DIR = Path(os.environ.get("RAG_APP_CACHE_DIR", CACHE_DIR / "app")) INDEX_CONFIG_PATH = Path(os.environ.get("RAG_INDEX_CONFIG", CONFIGS_DIR / "index_config.json")) # Required at query/generation time. On a Space this comes from a Space secret; # locally, set it in a .env file or the shell environment. GROQ_API_KEY = os.environ.get("GROQ_API_KEY") or None # Optional: used by the LLM-as-Judge evaluator when "OpenAI" eval method is selected. # Set as a Hugging Face Space secret named OPENAI_API_KEY, or in a local .env file. OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY") or None # Optional: OpenRouter API key for accessing models via openrouter.ai. # Set as a Hugging Face Space secret named OPENROUTER_API_KEY, or in a local .env file. OPENROUTER_API_KEY = os.environ.get("OPENROUTER_API_KEY") or None # Only needed if the Hugging Face dataset repo holding precomputed indices is private. # An empty string (e.g. an unset "HF_TOKEN=" line in .env) is treated as unset -- # huggingface_hub rejects a literal empty-string token with "Illegal header value". HF_TOKEN = os.environ.get("HF_TOKEN") or None for _dir in (INDICES_DIR, RESULTS_DIR, APP_CACHE_DIR): _dir.mkdir(parents=True, exist_ok=True)