route: broaden metric heuristics

This commit is contained in:
Brad Stein 2026-02-03 14:30:53 -03:00
parent 46fdebbbfb
commit ca717253f1

View File

@ -217,7 +217,8 @@ class AnswerEngine:
classify.setdefault("focus_entity", "unknown") classify.setdefault("focus_entity", "unknown")
classify.setdefault("focus_metric", "unknown") classify.setdefault("focus_metric", "unknown")
_debug_log("route_parsed", {"classify": classify, "normalized": normalized}) _debug_log("route_parsed", {"classify": classify, "normalized": normalized})
force_metric = bool(re.search(r"\bhow many\b|\bcount\b|\btotal\b", normalized.lower())) lowered_question = f"{question} {normalized}".lower()
force_metric = bool(re.search(r"\bhow many\b|\bcount\b|\btotal\b", lowered_question))
cluster_terms = ( cluster_terms = (
"atlas", "atlas",
"cluster", "cluster",
@ -241,7 +242,7 @@ class AnswerEngine:
"pvc", "pvc",
"storage", "storage",
) )
if any(term in normalized.lower() for term in cluster_terms): if any(term in lowered_question for term in cluster_terms):
classify["needs_snapshot"] = True classify["needs_snapshot"] = True
lowered_norm = normalized.lower() lowered_norm = normalized.lower()
if ( if (
@ -251,11 +252,19 @@ class AnswerEngine:
): ):
classify["question_type"] = "metric" classify["question_type"] = "metric"
classify["needs_snapshot"] = True classify["needs_snapshot"] = True
if re.search(r"\b(how many|count|number of|list)\b", normalized.lower()): if re.search(r"\b(how many|count|number of|list)\b", lowered_question):
classify["question_type"] = "metric" classify["question_type"] = "metric"
if any(term in lowered_question for term in ("postgres", "connections", "db")):
classify["question_type"] = "metric"
classify["needs_snapshot"] = True
if any(term in lowered_question for term in ("pvc", "persistentvolume", "persistent volume", "storage")):
if classify.get("question_type") not in {"metric", "diagnostic"}:
classify["question_type"] = "metric"
classify["needs_snapshot"] = True
if "ready" in lowered_question and classify.get("question_type") not in {"metric", "diagnostic"}:
classify["question_type"] = "diagnostic"
hottest_terms = ("hottest", "highest", "lowest", "most") hottest_terms = ("hottest", "highest", "lowest", "most")
metric_terms = ("cpu", "ram", "memory", "net", "network", "io", "disk", "load", "usage", "pod", "pods", "namespace") metric_terms = ("cpu", "ram", "memory", "net", "network", "io", "disk", "load", "usage", "pod", "pods", "namespace")
lowered_question = f"{question} {normalized}".lower()
if any(term in lowered_question for term in hottest_terms) and any(term in lowered_question for term in metric_terms): if any(term in lowered_question for term in hottest_terms) and any(term in lowered_question for term in metric_terms):
classify["question_type"] = "metric" classify["question_type"] = "metric"