knowledge: PR-3 skim notices to the loop + bounded lead promotion

PR-1 made the skim SEE (surfaces + signals); PR-2 made it HARVEST
deterministically. PR-3 closes the loop (KNOWLEDGE.md §7):

- Skim notices: every knowledge answer's stats carry what the fetched
  articles contained beyond the answer (table identities, infobox
  quantities, link candidates, goal-filtered). The engine copies them
  into payload['skim']; the machine renders them to the ROUTER context
  ('seen in passing (E1): ...') and to the run notes — later steps know
  what exists and where it lives instead of re-searching blind. A notice
  is a pointer, never evidence: it answers nothing by itself.
- Bounded lead promotion (Emili's 'deterministic + LLM fallback'):
  quantity tables that match NO goal word are queued as leads (PR-2);
  now ONE dspy call (SkimPromoteSignature) decides over the tables'
  IDENTITY lines (caption/headers/rows/quantities — never the rows),
  per fetched page with leads, only when leads exist. The LLM proposes;
  fixed code disposes: a promoted table still passes the entity-overlap
  check (a world discharge table is refused for Po/Adige/Tiber), the
  named column must exist, and ingestion goes through the same
  containment-checked _ingest_scalar_table as the deterministic path.
- Refactor: row ingestion extracted to _ingest_scalar_table (shared by
  harvest + promotion); _entity_overlap_count shared; skim state
  (_skim_notices/_skim_leads/_current_goal_question) reset per call.
- find_quantities: fix plain-digit quantities ('1540 m3/s', '1000 m3/s')
  — the thousands-separator-only regex missed them, and caption+header
  now join with a space ('m3/sRiver' broke the unit boundary).

Live smoke (real Wikipedia, scripted decision): goal terms without
'flow' queue both Italy tables as leads; the promoted 'Flow at the
mouth' table ingests all 27 rivers (Po 1540, Adige 235, Tiber 239
m3/s) containment-checked; promotion of the length table with a
'Flow' column name is refused (column does not exist).

Tests: 4 new (knowledge/tests/promote.py); suite 43/43 green.
This commit is contained in:
2026-10-20 16:24:43 +02:00
parent be320fd6a3
commit 1ebb4cfc0d
7 changed files with 391 additions and 74 deletions
+7
View File
@@ -139,6 +139,13 @@ class KnowledgeEngine:
payload["list_count"] = ans.get("list_count", len(ans["list_items"]))
if ans.get("coverage"):
payload["coverage"] = ans["coverage"]
# PR-3 — the skim notice: what the fetched articles contained beyond
# this answer (tables/infobox/link surfaces with goal signals). A
# POINTER for later steps, not evidence: it never answers a question,
# it tells the router what exists and where it lives.
skim_notices = (ans.get("stats") or {}).get("skim") or []
if skim_notices:
payload["skim"] = skim_notices[:3]
prov = {"expert": "knowledge", "source": src,
"note": ("source-verified: verbatim containment in trusted doc"
if ans.get("quote") else "no quote — unverified")}
+13 -2
View File
@@ -435,6 +435,10 @@ class FloopRun:
# fan-out bookkeeping: entity rows carry the group so the join finds them
if q.fan_group:
row.provenance["fan_group"] = q.fan_group
# PR-3: skim notices also land in the run notes — legibility law:
# derived answers render CONTENT, not counts alone
for n in (row.payload.get("skim") or [])[:2]:
self.notes.append(f"{q.qid}: skim: {n[:150]}")
self.table.append(row)
if str(row.payload.get("value", "")).strip().upper() == "UNKNOWN":
q.status = "failed"
@@ -445,7 +449,9 @@ class FloopRun:
def _context(self, q: OpenQuestion) -> str:
"""What the router sees. A list row renders its ITEMS — 'E1: 50' is
an ambiguous scalar that routes 'those countries' questions to the
user; 'E1: list of 50 items: Albania, ...' answers them."""
user; 'E1: list of 50 items: Albania, ...' answers them. Skim notices
(PR-3) render as 'seen in passing' pointers — the router knows what
exists and where it lives, without treating it as answered evidence."""
def render(r) -> str:
if isinstance(r.payload.get("list_items"), list):
return (f"list of {r.payload['list_count']} items: "
@@ -453,9 +459,12 @@ class FloopRun:
return str(r.payload.get("value", r.payload.get("quote", "")))
lines = []
notices = []
for d in q.deps:
for r in self.table.for_question(d):
lines.append(f"{r.eid} (answers {r.qid}): {render(r)}")
for n in (r.payload.get("skim") or [])[:2]:
notices.append(f"seen in passing ({r.eid}): {n}")
if not lines:
# no declared deps: the router must still SEE what the machine
# holds — an empty context routes referential questions to the
@@ -464,7 +473,9 @@ class FloopRun:
if r.retracted:
continue
lines.append(f"{r.eid} (answers {r.qid}): {render(r)}")
return "\n".join(lines[:8])
for n in (r.payload.get("skim") or [])[:2]:
notices.append(f"seen in passing ({r.eid}): {n}")
return "\n".join(lines[:8] + notices[:4])
# ---- answer ------------------------------------------------------------