config_loader.py
1.7 KB
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
"""
Compatibility wrapper for search-behavior config access.
The unified loader lives in :mod:`config.loader`. This module now exposes the
search subtree only, so existing search/indexer code can consume a single
source-of-truth search config without reparsing YAML separately.
"""
from __future__ import annotations
from dataclasses import asdict
from pathlib import Path
from typing import Any, Dict, List, Optional
from config.loader import AppConfigLoader, ConfigurationError
from config.schema import (
FunctionScoreConfig,
IndexConfig,
QueryConfig,
RerankConfig,
SPUConfig,
SearchConfig,
)
class ConfigLoader:
"""Load the unified app config and return the search subtree."""
def __init__(self, config_file: Optional[Path] = None) -> None:
self._loader = AppConfigLoader(config_file=Path(config_file) if config_file is not None else None)
def load_config(self, validate: bool = True) -> SearchConfig:
return self._loader.load(validate=validate).search
def validate_config(self, config: SearchConfig) -> List[str]:
errors: List[str] = []
if not config.es_index_name:
errors.append("es_index_name is required")
if not config.field_boosts:
errors.append("field_boosts is empty")
if config.query_config.default_language not in config.query_config.supported_languages:
errors.append("default_language must be included in supported_languages")
if config.spu_config.enabled and not config.spu_config.spu_field:
errors.append("spu_field is required when SPU is enabled")
return errors
def to_dict(self, config: SearchConfig) -> Dict[str, Any]:
return asdict(config)