knowledge: replace curated-vocab ambiguity audit with ablation detector (run J)

PR-7's audit (merged hours earlier) detected office ambiguity with a
curated role vocabulary (president, prime minister, ...) plus entity
and shape heuristics. His run-K log killed it: all three alternatives
came out '[prime minister]', Mariano Rajoy (a person, not an office)
was one, PSOE never appeared — the vocabulary could not see the
difference. His design replaces it, and it is better: instead of
listing what counts as a role, ask the judge whether the question
STILL answers once the support for the picked value is masked out.

_audit_ambiguity (knowledge/expert.py), zero new prompts:
- After a scalar KG answer V, find V's support rows (dst/quote carry
  the value) and MASK them from the view — the store is never
  mutated, the mask is a Python-level view.
- Re-ask the SAME judge (AnswerFromKG) on the surviving rows.
  A DIFFERENT value = a second defensible reading -> record, mask
  its support too, repeat (ambiguity_rounds=3, budget law).
- Same surviving value = corroboration -> silent stop.
- UNKNOWN -> clean answer, byte-identical to pre-audit behaviour.
- Run J: pick 'Socialist International' -> ablation surfaces
  'prime minister of Spain' then 'secretary-general of PSOE' — the
  third paragraph reading, no role vocabulary anywhere.

Removed: knowledge/ambiguity.py + knowledge/tests/ambiguity.py
(PR-7), the .ambiguity import, and _maybe_ambig at the three scalar
return paths — replaced by _audit_ambiguity(question, answer, rows,
charge_llm) at the same three sites.

Consumers (engine/machine) now render the simpler alternative shape
{value, quote, url} — no 'role' field exists to render.

Tests: knowledge/tests/ablation.py — the 4 agreed cases (2 Pedro
positives flag with 2 alternatives each, EU and rivers
counterexamples silent), corroboration-not-ambiguity, store
unchanged after audit (mask is a view), single-source silent, rounds
cap. Suite 70/70. Live smoke: full pipeline over the run-J page
picks SI and flags PM+SG via two ablation rounds; the rivers
question over the same KG stays silent.
This commit is contained in:
2026-10-21 23:42:20 +02:00
parent 599188181c
commit 8b50e3076e
6 changed files with 353 additions and 496 deletions
+1 -1
View File
@@ -184,7 +184,7 @@ class KnowledgeEngine:
f"{(ans.get('quote') or '')[:60]} url="
f"{ans.get('url') or ''} [{src}]")
elif ans.get("ambiguous"):
alts = "; ".join(f"[{a.get('role')}] {a.get('value')}"
alts = "; ".join(a.get("value", "")
for a in (ans.get("alternatives") or [])[:3])
streams.output("EXPERT",
f"{qref} -> ANSWER value={value} "
+2 -3
View File
@@ -458,7 +458,7 @@ class FloopRun:
self.notes.append(
f"{q.qid}: AMBIGUOUS: {row.payload.get('axis')} — "
f"other readings: " + "; ".join(
f"{a.get('value')} ({a.get('role')})" for a in alts[:3]))
a.get("value") for a in alts[:3]))
self.table.append(row)
if str(row.payload.get("value", "")).strip().upper() == "UNKNOWN":
q.status = "failed"
@@ -479,8 +479,7 @@ class FloopRun:
val = str(r.payload.get("value", r.payload.get("quote", "")))
if r.payload.get("ambiguous"):
alts = r.payload.get("alternatives") or []
other = "; ".join(f"{a.get('value')} ({a.get('role')})"
for a in alts[:3])
other = "; ".join(a.get("value", "") for a in alts[:3])
return (f"{val} — AMBIGUOUS, other defensible readings: "
f"{other}")
return val