From 18881ad5f9a606cdceceae18ef7dce3a8b7c68ff Mon Sep 17 00:00:00 2001 From: Shreyas Date: Fri, 20 Nov 2026 14:57:11 +0530 Subject: [PATCH] fix(mcp): don't route every "current"/"supported" question to release notes The router sent any docs query containing "current" or "supported" down the latest-release path: release notes only, sorted by date, no reranker. How-to questions like "Is dsl.ParallelFor supported in KFP v2?" or "How do I get the current run ID inside a KFP component?" got release notes back instead of the docs pages that answer them. "latest", "newest" and "most recent" still always count. "current" and "supported" now only count within three words of "version" or "release", so "current version of KFP", "supported Kubernetes versions" and "Which release is current?" still search release notes. The check is a small helper next to the existing regex rather than a change to the regex itself, so it doesn't touch the lines #290 changes. Fixes #289 Signed-off-by: Shreyas --- docs-agent-mcp/mcp-server/intent_router.py | 27 ++++++++++- docs/RAG_V4_ARCHITECTURE.md | 2 +- tests/test_intent_router_temporal.py | 52 ++++++++++++++++++++++ 3 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 tests/test_intent_router_temporal.py diff --git a/docs-agent-mcp/mcp-server/intent_router.py b/docs-agent-mcp/mcp-server/intent_router.py index a3cafd9a..274ac43b 100644 --- a/docs-agent-mcp/mcp-server/intent_router.py +++ b/docs-agent-mcp/mcp-server/intent_router.py @@ -32,6 +32,15 @@ r"\b(?:error|exception|errno|failed|failure|timeout|crashloop|oom)\b", re.I, ) +# "current" and "supported" also show up in everyday how-to questions ("the current run ID", +# "is ParallelFor supported in v2?"). On their own they only ask about the latest release +# when they sit within a few words of "version" or "release". +AMBIGUOUS_LATEST_WORDS = {"current", "supported"} +CURRENT_OR_SUPPORTED_NEAR_RELEASE = re.compile( + r"\b(?:current|supported)\W+(?:\w+\W+){0,3}?(?:versions?|releases?)\b" + r"|\b(?:versions?|releases?)\W+(?:\w+\W+){0,3}?(?:current|supported)\b", + re.I, +) @dataclass(frozen=True) @@ -86,6 +95,19 @@ def downgrade_plan_for_collection( return plan +def asks_for_latest_release(query: str) -> bool: + """True when the query asks about the latest release, not when it only uses the word. + + "latest", "newest" and "most recent" always count. "current" and "supported" count + only near "version" or "release": "current version of KFP" does, "the current run ID" + does not. + """ + words = {word.lower() for word in LATEST_OR_CURRENT_WORDS.findall(query)} + if words - AMBIGUOUS_LATEST_WORDS: + return True + return bool(words) and bool(CURRENT_OR_SUPPORTED_NEAR_RELEASE.search(query)) + + def pick_search_plan(query: str) -> RetrievalPlan: """First matching branch wins. Same rules as before.""" versions = VERSION_NUMBER.findall(query) @@ -109,8 +131,9 @@ def pick_search_plan(query: str) -> RetrievalPlan: prefer_version_match=True, ) - # "Latest / current / newest" — keyword search release notes, then sort by date. - if LATEST_OR_CURRENT_WORDS.search(query): + # "Latest / newest", or "current / supported" next to version/release — keyword search + # release notes, then sort by date. + if asks_for_latest_release(query): return RetrievalPlan( intent="temporal", retrieval_mode="bm25", diff --git a/docs/RAG_V4_ARCHITECTURE.md b/docs/RAG_V4_ARCHITECTURE.md index 828dc6b1..45a2165f 100644 --- a/docs/RAG_V4_ARCHITECTURE.md +++ b/docs/RAG_V4_ARCHITECTURE.md @@ -119,7 +119,7 @@ Deterministic rules in MCP when `SEARCH_MODE=auto`. No LLM involvement. Legacy c | Intent | Triggers (examples) | Mode | Post-search | | --- | --- | --- | --- | -| **temporal** | `latest`, `current`, `newest`, `most recent` | **bm25** | Filter `doc_type=release`; rerank by `release_date` DESC | +| **temporal** | `latest`, `newest`, `most recent`; `current` / `supported` only near `version` / `release` (e.g. "current version") | **bm25** | Filter `doc_type=release`; rerank by `release_date` DESC | | **release_date** | `when was`, `release date`, `released` + version | **bm25** | Prefer matching `version` chunk | | **lexical / exact** | Semver literals, config keys, error strings | **bm25** | — | | **conceptual** | `how`, `why`, `explain`, `overview`, `architecture` | **hybrid** (0.3 dense / 0.7 sparse, depth 50) | Weighted ranker | diff --git a/tests/test_intent_router_temporal.py b/tests/test_intent_router_temporal.py new file mode 100644 index 00000000..f9706cdc --- /dev/null +++ b/tests/test_intent_router_temporal.py @@ -0,0 +1,52 @@ +"""Tests for the temporal (latest/current/supported) rule in intent_router.pick_search_plan.""" + +import sys +from pathlib import Path + +import pytest + +sys.path.insert(0, str(Path(__file__).parent.parent / "docs-agent-mcp" / "mcp-server")) + +from intent_router import pick_search_plan + + +@pytest.mark.parametrize( + "query", + [ + # tests/eval/flo_eval_dataset.json: fid-latest-release + "What is the latest Kubeflow release?", + "newest Katib release", + # tests/eval/flo_eval_dataset.json: fid-current-kfp + "What is the current version of Kubeflow Pipelines?", + # keyword form the system prompt asks the model to send + "Kubeflow Pipelines current version", + "supported Kubernetes versions for Kubeflow", + "Which release is current?", + ], +) +def test_release_questions_search_release_notes(query): + plan = pick_search_plan(query) + assert plan.intent == "temporal" + assert plan.filter_expr == 'doc_type == "release"' + assert plan.rerank_by_release_date + + +@pytest.mark.parametrize( + "query", + [ + # tests/eval/flo_eval_dataset.json: fid-parallelfor-v2 + "Is dsl.ParallelFor supported in KFP v2?", + # tests/eval/flo_eval_dataset.json: dbg-external-mysql + "Is running Kubeflow Pipelines with an external MySQL supported, and how is it configured?", + "How do I get the current run ID inside a KFP component?", + "Which hyperparameter search algorithms are supported by Katib?", + # keyword forms of the two questions above + "KFP current run ID component", + "Katib supported search algorithms", + ], +) +def test_current_or_supported_alone_does_not_force_release_notes(query): + plan = pick_search_plan(query) + assert plan.intent != "temporal" + assert plan.filter_expr == "" + assert not plan.rerank_by_release_date