haiku.rag/haiku_rag_slim/haiku/rag/chunkers/__init__.py
Yiorgis Gozadinos e8f00fcff4
Make get_config the only configuration lookup
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().
2026-08-19 14:43:40 +03:00

32 lines
1 KiB
Python

"""Document chunker abstraction for haiku.rag."""
from haiku.rag.chunkers.base import DocumentChunker
from haiku.rag.config import AppConfig, get_config
__all__ = ["DocumentChunker", "get_chunker"]
def get_chunker(config: AppConfig | None = None) -> DocumentChunker:
"""Get a document chunker instance based on configuration.
Args:
config: Configuration to use. Defaults to the current global config.
Returns:
DocumentChunker instance configured according to the config.
Raises:
ValueError: If the chunker provider is not recognized.
"""
config = config if config is not None else get_config()
if config.processing.chunker == "docling-local":
from haiku.rag.chunkers.docling_local import DoclingLocalChunker
return DoclingLocalChunker(config)
if config.processing.chunker == "docling-serve":
from haiku.rag.chunkers.docling_serve import DoclingServeChunker
return DoclingServeChunker(config)
raise ValueError(f"Unsupported chunker: {config.processing.chunker}")