diff --git a/haiku_rag_slim/haiku/rag/app.py b/haiku_rag_slim/haiku/rag/app.py index 856745dd..8a73919d 100644 --- a/haiku_rag_slim/haiku/rag/app.py +++ b/haiku_rag_slim/haiku/rag/app.py @@ -891,7 +891,7 @@ class HaikuRAGApp: f"[repr.attrib_name]chunk_id[/repr.attrib_name]: {result.chunk_id} " f"[repr.attrib_name]score[/repr.attrib_name]: {result.score:.4f}" ) - if result.source and len(self.config.lancedb.databases) > 1: + if result.source and self.scope.covers_multiple: self.console.print( f"[repr.attrib_name]database[/repr.attrib_name]: {result.source}" ) diff --git a/tests/test_app.py b/tests/test_app.py index c366dddd..6714f841 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -11,6 +11,7 @@ from rich.console import Console from haiku.rag.app import HaikuRAGApp from haiku.rag.client import RebuildMode +from haiku.rag.client.scope import DatabaseScope from haiku.rag.config.models import ( AppConfig, LanceDBConfig, @@ -200,6 +201,34 @@ async def test_search_prints_results(app, client): assert "hit one" in out(app) +async def test_a_result_names_its_database_only_across_several(tmp_path): + """The label answers what this operation covers, not what is configured: + after narrowing to one, the caller has already named it.""" + config = AppConfig( + lancedb=LanceDBConfig( + databases={ + "alpha": str(tmp_path / "a.lancedb"), + "beta": str(tmp_path / "b.lancedb"), + } + ) + ) + hit = SearchResult(content="hit", score=0.9, chunk_id="c1", source="alpha") + + covering = HaikuRAGApp(scope=DatabaseScope.resolve(config), config=config) + covering.console = Console(record=True, width=200) + covering._rich_print_search_result(hit) + assert "database: alpha" in covering.console.export_text() + + narrowed = HaikuRAGApp( + scope=DatabaseScope.resolve(config, database_name="alpha"), config=config + ) + narrowed.console = Console(record=True, width=200) + narrowed._rich_print_search_result(hit) + printed = narrowed.console.export_text() + assert "hit" in printed + assert "database:" not in printed + + async def test_search_by_image_reads_the_bytes(app, client, tmp_path): image = tmp_path / "query.png" image.write_bytes(b"pixels") diff --git a/tests/test_cli.py b/tests/test_cli.py index d6e9f7cc..ebc13109 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -749,12 +749,13 @@ class TestRenderingTheDatabase: @staticmethod def _app(tmp_path, **databases): + """An app over the configured set. The scope is what decides the label, + so it has to be the one the configuration resolves to.""" from haiku.rag.app import HaikuRAGApp + from haiku.rag.client.scope import DatabaseScope - return HaikuRAGApp( - scope=for_path(tmp_path / "unused"), - config=AppConfig(lancedb=LanceDBConfig(databases=databases)), - ) + config = AppConfig(lancedb=LanceDBConfig(databases=databases)) + return HaikuRAGApp(scope=DatabaseScope.resolve(config), config=config) @staticmethod def _rendered(app, result) -> str: