From 34da7a18f4c337c75f17f9825832ff0ef1e5be1d Mon Sep 17 00:00:00 2001 From: CodexManvik Date: Sun, 8 Nov 2026 23:30:32 +0530 Subject: [PATCH] Route single-number questions to custom SQL; benchmark the no-data case The first live benchmark scored 28/30. The LLM router sent "How many profiles were recorded in the Arabian Sea?" to the per-float summary table, so the intent descriptions now say that counts, totals, maxima and minima need their own SQL. The Red Sea question failed only because the live data has no Red Sea profiles; FloatChat correctly said so. The case now expects exactly that honest "no profiles were recorded" answer. Co-Authored-By: Claude Opus 5.5 --- eval/questions.json | 4 ++-- eval/runner.py | 12 +++++++++--- floatchat/router.py | 5 +++-- tests/unit/test_eval.py | 11 +++++++++++ 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/eval/questions.json b/eval/questions.json index 8db6fd6..16bc124 100644 --- a/eval/questions.json +++ b/eval/questions.json @@ -46,8 +46,8 @@ "expect": {"path": "semantic", "filters": {"region": "Southern Indian Ocean", "has_chlorophyll": true}}}, {"id": "find-indonesia-january", "question": "Profiles near Indonesia in January 2026", "expect": {"path": "semantic", "filters": {"region": "Eastern Indian Ocean", "month_num": 1, "year": 2026}}}, - {"id": "find-red-sea", "question": "Describe recent profiles from the Red Sea", - "expect": {"path": "semantic", "filters": {"region": "Red Sea & Gulf of Aden"}}}, + {"id": "no-data-red-sea", "question": "Describe recent profiles from the Red Sea", + "expect": {"path": "semantic", "filters": {"region": "Red Sea & Gulf of Aden"}, "no_match": true}}, {"id": "find-nitrate-arabian", "question": "Find nitrate measurements in the Arabian Sea", "expect": {"path": "semantic", "filters": {"region": "Arabian Sea", "has_nitrate": true}}}, {"id": "find-thermocline", "question": "Show me profiles with a strong thermocline", diff --git a/eval/runner.py b/eval/runner.py index 056c4ff..db86e84 100644 --- a/eval/runner.py +++ b/eval/runner.py @@ -64,11 +64,17 @@ def _check_analytical(response: dict) -> str | None: return f"SQL does not apply {', '.join(missing)}" if missing else None -def _check_semantic(response: dict) -> str | None: +def _check_semantic(response: dict, expect_no_match: bool = False) -> str | None: + widened = any(s.get("step") == "search" and s.get("fallback_without_filters") for s in response.get("steps") or []) + if expect_no_match: + # The dataset has nothing matching: the answer must say so rather than present other profiles as matches + if not widened or not response.get("answer", "").startswith("No profiles were recorded"): + return "should have said no profiles match" + return None profiles = response.get("retrieved_metadata") or [] if not profiles: return "no profiles returned" - if any(s.get("step") == "search" and s.get("fallback_without_filters") for s in response.get("steps") or []): + if widened: return "no profile matched the filters (search was widened)" filters = response.get("filters") or {} wrong = sum(not _profile_matches(p, filters) for p in profiles) @@ -116,7 +122,7 @@ def check_case(case: dict, status: int, response: dict, latency_ms: int) -> dict elif response.get("query_type") == "analytical": problem = _check_analytical(response) else: - problem = _check_semantic(response) + problem = _check_semantic(response, expect.get("no_match", False)) result["answer"] = problem is None notes = [] if not result["routing"]: diff --git a/floatchat/router.py b/floatchat/router.py index ed2fd9a..36b6568 100644 --- a/floatchat/router.py +++ b/floatchat/router.py @@ -22,9 +22,10 @@ "regional_comparison": "compare the regions (upper 100 m)", "depth_ranges": "averages by depth layer (surface, intermediate, deep)", "temporal_trends": "monthly averages over time", - "float_summary": "statistics per float, most active floats", + "float_summary": "a table with one row per float (its profile count, averages, depth), e.g. most active floats", "bgc_analysis": "oxygen, chlorophyll, nitrate or pH by ocean zone", - "custom": "any other statistical question that needs its own SQL", + "custom": "any other statistical question that needs its own SQL, including a single number such as a count, " + "total, maximum or minimum (e.g. 'how many profiles…', 'what was the highest temperature…')", } diff --git a/tests/unit/test_eval.py b/tests/unit/test_eval.py index 99cfc40..0abe41a 100644 --- a/tests/unit/test_eval.py +++ b/tests/unit/test_eval.py @@ -75,6 +75,17 @@ def test_semantic_answers_must_only_return_matching_profiles(): assert check_case(FIND, 200, semantic([]), 10)["answer"] is False +def test_a_no_match_case_passes_only_when_the_answer_says_nothing_matched(): + case = {**FIND, "expect": {**FIND["expect"], "no_match": True}} + honest = semantic([bengal(region="Arabian Sea")], fallback=True) + honest["answer"] = "No profiles were recorded in the Bay of Bengal in this dataset, so these are the closest..." + assert check_case(case, 200, honest, 10)["answer"] is True + pretends = semantic([bengal(region="Arabian Sea")], fallback=True) + pretends["answer"] = "Here are the Bay of Bengal profiles..." + assert check_case(case, 200, pretends, 10)["answer"] is False + assert check_case(case, 200, semantic([bengal()]), 10)["answer"] is False + + def test_optional_filters_are_ignored_when_comparing(): assert check_case(FIND, 200, semantic([bengal()]), 10)["filters"] is True assert check_case(FIND, 200, semantic([bengal()], filters={"region": "Bay of Bengal"}), 10)["filters"] is True