haiku.rag.config exported two configuration instances: the lazy _config behind get_config/set_config, and Config, loaded at import time. Nothing linked them, and eleven signatures captured Config as a default argument, so set_config could not reach the factories, the client, the store or the MCP server. reranking/base.py went further and snapshotted the configured reranker name into a class attribute at import. Config is removed. Internal defaults are config: AppConfig | None = None, resolved through get_config() per call. RerankerBase._model is None and CohereReranker takes its model name as an argument, like every other reranker. The suite patched attributes on Config while production read the instance get_config() returns, a different object, so those patches were no-ops waiting to happen. They now go through get_config().
99 lines
2.2 KiB
Python
99 lines
2.2 KiB
Python
from haiku.rag.config.loader import (
|
|
MissingEnvVarError,
|
|
expand_env_vars,
|
|
find_config_file,
|
|
generate_default_config,
|
|
load_yaml_config,
|
|
redact_secrets,
|
|
)
|
|
from haiku.rag.config.models import (
|
|
APIConfig,
|
|
AppConfig,
|
|
CircuitBreakerConfig,
|
|
ConversionOptions,
|
|
DoclingServeConfig,
|
|
EmbeddingModelConfig,
|
|
EmbeddingsConfig,
|
|
FSSourceConfig,
|
|
HTTPSourceConfig,
|
|
IngesterConfig,
|
|
LanceDBConfig,
|
|
ModelConfig,
|
|
OllamaConfig,
|
|
PluginSourceConfig,
|
|
ProcessingConfig,
|
|
PromptsConfig,
|
|
ProvidersConfig,
|
|
QAConfig,
|
|
QueueConfig,
|
|
RerankingConfig,
|
|
RetryPolicyConfig,
|
|
S3SourceConfig,
|
|
SourceConfig,
|
|
StorageConfig,
|
|
WebDAVSourceConfig,
|
|
WorkerConfig,
|
|
)
|
|
|
|
__all__ = [
|
|
"APIConfig",
|
|
"AppConfig",
|
|
"CircuitBreakerConfig",
|
|
"ConversionOptions",
|
|
"DoclingServeConfig",
|
|
"EmbeddingModelConfig",
|
|
"EmbeddingsConfig",
|
|
"FSSourceConfig",
|
|
"HTTPSourceConfig",
|
|
"IngesterConfig",
|
|
"LanceDBConfig",
|
|
"ModelConfig",
|
|
"OllamaConfig",
|
|
"PluginSourceConfig",
|
|
"ProcessingConfig",
|
|
"PromptsConfig",
|
|
"ProvidersConfig",
|
|
"QAConfig",
|
|
"QueueConfig",
|
|
"RerankingConfig",
|
|
"RetryPolicyConfig",
|
|
"S3SourceConfig",
|
|
"SourceConfig",
|
|
"StorageConfig",
|
|
"WebDAVSourceConfig",
|
|
"WorkerConfig",
|
|
"MissingEnvVarError",
|
|
"expand_env_vars",
|
|
"find_config_file",
|
|
"generate_default_config",
|
|
"get_config",
|
|
"load_yaml_config",
|
|
"redact_secrets",
|
|
"set_config",
|
|
]
|
|
|
|
# Global config instance - initially loads from default locations
|
|
_config: AppConfig | None = None
|
|
|
|
|
|
def _load_default_config() -> AppConfig:
|
|
"""Load config from the default locations."""
|
|
config_path = find_config_file(None)
|
|
if config_path:
|
|
yaml_data = load_yaml_config(config_path)
|
|
return AppConfig.model_validate(yaml_data)
|
|
return AppConfig()
|
|
|
|
|
|
def set_config(config: AppConfig) -> None:
|
|
"""Set the global config instance (used by CLI to override)."""
|
|
global _config
|
|
_config = config
|
|
|
|
|
|
def get_config() -> AppConfig:
|
|
"""Get the current config instance, loading it on first use."""
|
|
global _config
|
|
if _config is None:
|
|
_config = _load_default_config()
|
|
return _config
|