atlasbot: force hottest facts for hottest queries

This commit is contained in:
Brad Stein 2026-02-01 14:34:00 -03:00
parent 90423b6b10
commit 2eb726c274

View File

@ -266,8 +266,12 @@ class AnswerEngine:
scored = await _score_chunks(call_llm, chunks, normalized, sub_questions, plan) scored = await _score_chunks(call_llm, chunks, normalized, sub_questions, plan)
selected = _select_chunks(chunks, scored, plan, keyword_tokens) selected = _select_chunks(chunks, scored, plan, keyword_tokens)
key_facts = _key_fact_lines(summary_lines, keyword_tokens) key_facts = _key_fact_lines(summary_lines, keyword_tokens)
hottest_facts = _extract_hottest_facts(summary_lines, normalized)
metric_facts = [line for line in key_facts if re.search(r"\d", line)] metric_facts = [line for line in key_facts if re.search(r"\d", line)]
if classify.get("question_type") in {"metric", "diagnostic"}: if hottest_facts:
metric_facts = hottest_facts
key_facts = _merge_fact_lines(metric_facts, key_facts)
if classify.get("question_type") in {"metric", "diagnostic"} and not hottest_facts:
metric_candidates = _metric_candidate_lines(summary_lines, keyword_tokens) metric_candidates = _metric_candidate_lines(summary_lines, keyword_tokens)
selected_facts = await _select_metric_facts(call_llm, normalized, metric_candidates, plan) selected_facts = await _select_metric_facts(call_llm, normalized, metric_candidates, plan)
if selected_facts: if selected_facts:
@ -1008,6 +1012,34 @@ def _expand_hottest_line(line: str) -> list[str]:
return expanded return expanded
def _extract_hottest_facts(lines: list[str], question: str) -> list[str]:
if not lines:
return []
lowered = question.lower()
if not any(term in lowered for term in ("hottest", "highest", "lowest", "most")):
return []
line = next((item for item in lines if item.lower().startswith("hottest:")), "")
if not line:
return []
facts = _expand_hottest_line(line)
if not facts:
return []
wanted = []
if any(term in lowered for term in ("cpu", "processor")):
wanted.append("hottest_cpu_node")
if any(term in lowered for term in ("ram", "memory")):
wanted.append("hottest_ram_node")
if any(term in lowered for term in ("net", "network", "throughput")):
wanted.append("hottest_net_node")
if "io" in lowered or "i/o" in lowered:
wanted.append("hottest_io_node")
if "disk" in lowered or "storage" in lowered:
wanted.append("hottest_disk_node")
if not wanted:
return facts
return [fact for fact in facts if any(label in fact for label in wanted)] or facts
def _metric_candidate_lines(lines: list[str], keywords: list[str] | None, limit: int = 40) -> list[str]: def _metric_candidate_lines(lines: list[str], keywords: list[str] | None, limit: int = 40) -> list[str]:
if not lines: if not lines:
return [] return []