File size: 871 Bytes
7eaced5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""config.py — Minimal config loader for the KG Explorer UI."""
from __future__ import annotations

import os
from pathlib import Path
from typing import Any

import yaml

_PROJECT_ROOT = Path(__file__).resolve().parent.parent
_DEFAULT_CONFIG = _PROJECT_ROOT / "config" / "config.yaml"


def load_config(config_path: str | Path | None = None) -> dict[str, Any]:
    path = Path(config_path) if config_path else _DEFAULT_CONFIG
    if not path.exists():
        raise FileNotFoundError(f"Config file not found: {path}")

    with open(path, "r", encoding="utf-8") as f:
        cfg: dict[str, Any] = yaml.safe_load(f)

    qdrant_api_key = os.environ.get("QDRANT_API_KEY")
    if qdrant_api_key:
        cfg["qdrant"]["api_key"] = qdrant_api_key

    qdrant_url = os.environ.get("QDRANT_URL")
    if qdrant_url:
        cfg["qdrant"]["url"] = qdrant_url

    return cfg