Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions docs-agent-mcp/mcp-server/intent_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion docs/RAG_V4_ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
52 changes: 52 additions & 0 deletions tests/test_intent_router_temporal.py
Original file line number Diff line number Diff line change
@@ -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