atlasbot: match metric facts by key

This commit is contained in:
Brad Stein 2026-02-04 14:04:43 -03:00
parent 70c7712b60
commit 9d034bb937

View File

@ -559,7 +559,7 @@ class AnswerEngine:
if any(term in lowered_question for term in hardware_terms) and hardware_line: if any(term in lowered_question for term in hardware_terms) and hardware_line:
needs_evidence = True needs_evidence = True
if metric_facts and (classify.get("question_type") in {"metric", "diagnostic"} or force_metric): if metric_facts and (classify.get("question_type") in {"metric", "diagnostic"} or force_metric):
if not _reply_matches_metric_facts(reply, metric_facts): if not _reply_matches_metric_facts(reply, metric_facts, all_tokens):
needs_evidence = True needs_evidence = True
if classify.get("question_type") in {"open_ended", "planning"} and metric_facts: if classify.get("question_type") in {"open_ended", "planning"} and metric_facts:
needs_evidence = True needs_evidence = True
@ -612,7 +612,7 @@ class AnswerEngine:
model=plan.model, model=plan.model,
tag="evidence_fix", tag="evidence_fix",
) )
if metric_facts and not _reply_matches_metric_facts(reply, metric_facts): if metric_facts and not _reply_matches_metric_facts(reply, metric_facts, all_tokens):
enforce_prompt = ( enforce_prompt = (
prompts.EVIDENCE_FIX_PROMPT prompts.EVIDENCE_FIX_PROMPT
+ "\nQuestion: " + "\nQuestion: "
@ -2273,7 +2273,7 @@ def _needs_evidence_fix(reply: str, classify: dict[str, Any]) -> bool:
return False return False
def _reply_matches_metric_facts(reply: str, metric_facts: list[str]) -> bool: def _reply_matches_metric_facts(reply: str, metric_facts: list[str], tokens: list[str] | set[str] | None = None) -> bool:
if not reply or not metric_facts: if not reply or not metric_facts:
return True return True
reply_numbers = set(re.findall(r"\d+(?:\\.\d+)?", reply)) reply_numbers = set(re.findall(r"\d+(?:\\.\d+)?", reply))
@ -2281,7 +2281,17 @@ def _reply_matches_metric_facts(reply: str, metric_facts: list[str]) -> bool:
return False return False
fact_numbers: set[str] = set() fact_numbers: set[str] = set()
value_pattern = re.compile(r"(?:>=|<=|=|:)\\s*(\\d+(?:\\.\\d+)?)") value_pattern = re.compile(r"(?:>=|<=|=|:)\\s*(\\d+(?:\\.\\d+)?)")
for line in metric_facts: filtered = metric_facts
if tokens:
token_set = {str(tok).lower() for tok in tokens if tok}
focused = []
for line in metric_facts:
key = line.split(":", 1)[0].lower()
if any(tok in key for tok in token_set):
focused.append(line)
if focused:
filtered = focused
for line in filtered:
for match in value_pattern.findall(line): for match in value_pattern.findall(line):
fact_numbers.add(match) fact_numbers.add(match)
if not fact_numbers: if not fact_numbers: