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().
23 lines
752 B
Python
23 lines
752 B
Python
from haiku.rag.store.models.chunk import Chunk
|
|
|
|
|
|
class RerankerBase:
|
|
_model: str | None = None
|
|
|
|
async def rerank(
|
|
self, query: str, chunks: list[Chunk], top_n: int = 10
|
|
) -> list[tuple[Chunk, float]]:
|
|
if not chunks:
|
|
return []
|
|
return await self._rerank(query, chunks, top_n)
|
|
|
|
async def _rerank(
|
|
self, query: str, chunks: list[Chunk], top_n: int = 10
|
|
) -> list[tuple[Chunk, float]]:
|
|
raise NotImplementedError(
|
|
"Reranker is an abstract class. Please implement the _rerank method in a subclass."
|
|
)
|
|
|
|
async def aclose(self) -> None:
|
|
"""Release resources held by the reranker. No-op by default;
|
|
rerankers that own an HTTP client override this."""
|