diff --git a/atlasbot/engine/answerer.py b/atlasbot/engine/answerer.py index ffb6d0d..22e5b4c 100644 --- a/atlasbot/engine/answerer.py +++ b/atlasbot/engine/answerer.py @@ -559,7 +559,7 @@ class AnswerEngine: if any(term in lowered_question for term in hardware_terms) and hardware_line: needs_evidence = True 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 if classify.get("question_type") in {"open_ended", "planning"} and metric_facts: needs_evidence = True @@ -612,7 +612,7 @@ class AnswerEngine: model=plan.model, 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 = ( prompts.EVIDENCE_FIX_PROMPT + "\nQuestion: " @@ -2273,7 +2273,7 @@ def _needs_evidence_fix(reply: str, classify: dict[str, Any]) -> bool: 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: return True 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 fact_numbers: set[str] = set() 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): fact_numbers.add(match) if not fact_numbers: