"""Validated server-side switches for controlled learned-engine experiments.""" from dataclasses import dataclass import os @dataclass(frozen=True) class LearnedSettings: matcher: str = 'loftr' max_size: int = 800 patches: str = 'single' adaptive_mask: bool = False @classmethod def from_env(cls): matcher = os.environ.get('IRIS_MATCHER', 'loftr') patches = os.environ.get('IRIS_PATCH_VALIDATION', 'single') adaptive = os.environ.get('IRIS_ADAPTIVE_MASK', 'false').lower() try: size = int(os.environ.get('IRIS_MATCH_MAX_SIZE', '800' if matcher=='loftr' else '1600')) except ValueError as exc: raise RuntimeError('IRIS_MATCH_MAX_SIZE must be an integer.') from exc if matcher not in {'loftr', 'lightglue'} or patches not in {'single', 'multiscale', 'geometry'}: raise RuntimeError('Invalid learned matcher or patch-validation configuration.') if adaptive not in {'true', 'false'}: raise RuntimeError('IRIS_ADAPTIVE_MASK must be true or false.') if not 400 <= size <= (1200 if matcher=='loftr' else 2200): raise RuntimeError('IRIS_MATCH_MAX_SIZE exceeds the supported range.') return cls(matcher, size, patches, adaptive=='true')