|
|
""" |
|
|
Centralized configuration helpers for the Mixedbread CVE RAG workflow. |
|
|
""" |
|
|
|
|
|
from __future__ import annotations |
|
|
|
|
|
import os |
|
|
from dataclasses import dataclass |
|
|
from pathlib import Path |
|
|
|
|
|
|
|
|
@dataclass |
|
|
class Settings: |
|
|
"""Container for frequently used paths and model configuration.""" |
|
|
|
|
|
project_root: Path |
|
|
zip_path: Path |
|
|
cve_root: Path |
|
|
corpus_path: Path |
|
|
chroma_dir: Path |
|
|
chroma_collection: str |
|
|
embed_model: str |
|
|
rerank_model: str |
|
|
hf_token: str |
|
|
embed_batch_size: int |
|
|
device: str |
|
|
|
|
|
def load_settings() -> Settings: |
|
|
root = Path(__file__).resolve().parents[1] |
|
|
data_root = root / "data" / "cvelistV5-main" |
|
|
artifacts_dir = root / "rag_mixedbread" / "artifacts" |
|
|
chroma_dir = root / "rag_mixedbread" / "index" |
|
|
|
|
|
hf_token = os.environ.get("HF_API_TOKEN", "") |
|
|
|
|
|
settings = Settings( |
|
|
project_root=root, |
|
|
zip_path=root / "testing" / "cvelistV5-main.zip", |
|
|
cve_root=data_root, |
|
|
corpus_path=artifacts_dir / "cve_corpus.jsonl", |
|
|
chroma_dir=chroma_dir, |
|
|
chroma_collection=os.environ.get("RAG_CHROMA_COLLECTION", "cve_chunks"), |
|
|
embed_model=os.environ.get( |
|
|
"RAG_EMBED_MODEL", "mixedbread-ai/mxbai-embed-large-v1" |
|
|
), |
|
|
rerank_model=os.environ.get( |
|
|
"RAG_RERANK_MODEL", "mixedbread-ai/mxbai-rerank-base-v2" |
|
|
), |
|
|
hf_token=hf_token, |
|
|
embed_batch_size=int(os.environ.get("RAG_EMBED_BATCH", "8")), |
|
|
device=os.environ.get("RAG_DEVICE", "cpu"), |
|
|
) |
|
|
|
|
|
artifacts_dir.mkdir(parents=True, exist_ok=True) |
|
|
chroma_dir.mkdir(parents=True, exist_ok=True) |
|
|
return settings |
|
|
|
|
|
|
|
|
__all__ = ["Settings", "load_settings"] |
|
|
|
|
|
|