From 9cfc068ad67f8d7a09a015d2c7064d36a181f3e6 Mon Sep 17 00:00:00 2001 From: Onibot Date: Sun, 25 Oct 2026 15:28:32 +0100 Subject: [PATCH] research: conflicts taxonomy + temporal restrictions + derived answers (design docs) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Findings from the 24-25/10 session (live runs, glm-5.3-flash): - The A/B (his question, cold KG): glm cloud 148s -> Rajoy; qwen local 50min -> honest UNKNOWN (KG held Rajoy; a noise row misled it). - The (K5) bug: judge value contamination kills the ablation audit silently; repro shows the detector works with a clean value. - dspy disk cache replays repeated runs (measurement law recorded). - The conflicts inventory: 20 pairs, zero real contradictions — the 4-case classifier conflates conjunction/paraphrase/temporal/polisemia. RESEARCH-derived-answers.md: the design growing from all of it: merge-time taxonomy (co-asserted / temporal / alternatives / real), temporal restrictions (not Allen labels) on the typed Fact extractor, and a derived-answer engine (typed query DSL + goal-directed proof, no LLM judge in the loop). Span: knowledge/ + floop/ — doc at code/. --- code/RESEARCH-derived-answers.md | 270 +++++++++++++++++++++++++ code/knowledge/RESEARCH-semantic-kg.md | 81 +++++++- 2 files changed, 350 insertions(+), 1 deletion(-) create mode 100644 code/RESEARCH-derived-answers.md diff --git a/code/RESEARCH-derived-answers.md b/code/RESEARCH-derived-answers.md new file mode 100644 index 0000000..23adb4c --- /dev/null +++ b/code/RESEARCH-derived-answers.md @@ -0,0 +1,270 @@ +# RESEARCH: derived answers — conflicts, time, and a prover instead of a judge + +Status: RESEARCH BRANCH (research/semantic-kg). Design doc, not code. +Opened: 2026-10-25, from the conflicts inventory + the (K5) session (see +RESEARCH-semantic-kg.md, "Findings from the live A/B and the (K5) bug"). + +Scope note: this spans more than knowledge/ — the conflict taxonomy and the +temporal layer live in the store (knowledge/), the extractor vocabulary in +the pipeline (knowledge/), but the derived-answer engine replaces the +AnswerFromKG judge inside the loop and talks to the machine, INIT and the +evidence table (floop/). Hence the doc lives at code/ level. + +The three findings this design grows from (all measured, live): + +1. 20 conflict pairs in the KG after one Pedro run, ZERO real + contradictions — the 4-case classifier conflates conjunction, + paraphrase, temporal succession, and genuine polisèmia. +2. The (K5) bug: the judge is the last place where an LLM DECIDES inside + the loop, and its interface bugs (value contamination) silently kill + the ambiguity audit. Multi-binding ambiguity is a SET question; a + judge forced to return ONE value is the wrong instrument for it. +3. The three-presidency ambiguity is detectable deterministically at + ingest (the conflicts table holds it pairwise), yet the system only + hears about it through an expensive, fragile judge-time audit. + +## Part 1 — the conflict taxonomy (merge-time, deterministic) + +Four buckets replace the single "contradiction" case. Ordered by signal +cost; each pair falls into the FIRST bucket whose signal it matches. + +### A. co-asserted (same quote_id) + +Both values come from the SAME verbatim quote. A trusted source asserting +A and B in one sentence means the world holds A and B: conjunction, not +conflict. Kills the 10 same-quote "called for" pairs on provenance alone. +Zero extra machinery: quote_id is already an edge column. + +### B. temporal succession + +Dates are stated in the text (inside the dst or the quote: "since YYYY", +"in YYYY", "from X to Y") but ref_date is empty, so _classify never sees +them. With the temporal layer (Part 2), windows are extracted at ingest +and the classification is interval arithmetic: disjoint windows → +succession (the "became" pair: Leader-of-Opposition in 2014, prime +minister in 2018). Overlapping windows → they coexist → bucket C. +Backfill: for existing conflicting pairs with empty windows, one +targeted re-extraction pass over their quotes (bounded by the conflict +count, not the corpus). + +### C. alternatives (the polisèmia) + +Different facts, co-true, from different discriminant entities. The +signal chain, all deterministic: + +- discriminant-token analysis: the two values differ not just in + order/articles/parenthetical expansions → not a paraphrase; +- tail resolution: the institution tails resolve to DIFFERENT nodes + ("prime minister of Spain" vs "Secretary-General of the PSOE") — + same store lookup/stemming the lexical probe already uses; +- value type: dst is an entity NAME (not a date/quantity) → the + relation is multi-valued by nature (a person holds many positions); + dst is a date for a date-like relation → functional → only one value + can be true → bucket D; +- functionality statistics: per-relation multi-value rate over the + growing store (date_of_birth never multi, position held often + multi) — an oracle of functionality earned by scale. Cold-store + fallback: type logic + co-assertion. + +THE THREE PRESIDENCIES are the type case: pairwise position-held +conflicts whose tails resolve to Spain / PSOE / SI. This bucket IS the +ambiguity substrate: what the ablation audit re-derives at judge-time +(re-asking an LLM per round) is already known here at ingest-time. The +flag, not the choice — the alternatives are served to whoever asks. + +### D. real contradiction + +Same src + functional rel + incompatible values, none of the above +applies. Two different birth dates. The honest conflict-exposed state of +the current design — expected to be RARE (none in the live inventory). + +### Paraphrase → merge (pre-bucket check) + +Before bucketing: same discriminant-free surface (modulo order, +articles, "(Spanish: …)" expansions) OR both tails resolve to the same +node OR both canonicalize to the same Wikipedia redirect target → SAME +FACT. Append-only law: merge is an alias/same_as edge, never a delete; +the canonical form guides retrieval, both surfaces remain queryable. + +### What embeddings do and do NOT do here + +Cosine measures TOPIC similarity, not fact identity: +"Prime Minister of Spain" vs "Prime Minister of France" ~0.9 — different +facts; "…of Spain" vs "president of the Government (Spanish: …)" ~0.65 +— same fact. A cosine threshold would merge France into Spain and miss +the real alias. Embeddings CONFIRM and RANK inside a bucket (best merge +candidate first); they never decide the bucket. The curated-semantics +channel is Wikipedia's redirect graph (already fetched, redirects=1) — +canonicalization grounded in a trusted source, not model weights. Same +law as everywhere else in floop: deterministic signals decide; the model +never does. + +## Part 2 — time on the KG + +### Representation + +- Edge columns (the Wikidata qualifier model): start, end, point, + granularity (year/month/day — "since 2022" is the interval + [2022, 2023), not a date). valid time (the fact's window) stays + distinct from fetched_at (transaction time), as today. +- fact_order(edge_a, edge_b, rel, quote_id) with rel ∈ {before, after, + concurrent}: ordering BETWEEN facts. Edges are already addressable + (integer ids) — reification comes free in a property graph; no fact + nodes to materialize. +- Open intervals: "since 2018" → end=open. The overlap of two open + intervals is PROVABLE coexistence — the polisèmia signal as interval + arithmetic (bucket C), per fact, no statistics needed. + +### The extractor's temporal vocabulary — RESTRICTIONS, not labels + +The extractor transcribes what the text COMMITS, as typed optional +fields on Fact (the feature/typed-facts BaseModel is the vehicle): + +- order: before / after / concurrent — asserted ONLY when the text has + the connective ("abans de", "alhora", "while", "també") and NO dates + would let code compute it; quotable, containment-checkable; +- duration: quantity + unit (the skim's quantity regex already knows); +- anchor: start/end → date | event-node ("fins que va dimitir de A" + anchors F1's end to an EVENT, not a date — events are addressable + nodes, dates resolve later by propagation); +- immediacy: bool ("l'endemà", "fins que"). + +Full Allen algebra is a COMPUTED VIEW, not an extraction target: with +endpoints extracted, overlaps/during/starts/finishes/meets are endpoint +arithmetic in the store. The text CAN carry the full gamut ("president +of A and B at the same time for a month until he resigned from A") but +what it carries is three RESTRICTIONS (concurrent F1–F2, duration 1 +month, F1.end anchored to the resignation event) — asking the model to +also CHOOSE an Allen label would (a) replace transcription with +classification, (b) produce labels with no quotable connective to check +against, (c) create a second channel of truth that silently disagrees +with the computed one 1% of the time, (d) invite confident labels at +granularity the prose lacks. Restrictions are honest (optional fields +stay empty when the text is silent), checkable (containment), and they +UPDATE: when a later source dates the resignation, the network +propagates and the Allen view recomputes itself — a label extracted on +day one never would. + +### Check + +Same law as facts: the temporal field must be contained in the quote +("2022" not in quote → reject the date; connective absent → reject the +order). LLM proposes, code verifies against the source surface. + +## Part 3 — the derived-answer engine (no judge in the loop) + +The end state he steered to: the component that generates the answer is +NOT an LLM. The LLMs translate at the two ends (question → logic on the +way in; proven object → prose later, outside the loop) and never in the +middle. This is the Logic-LM move of the lineage (lm→solver) applied to +floop's own layer, and the real prover the v0.1 map always listed as a +stub. + +### The query DSL (small, typed) + +The store's atoms are ground, containment-checked rows; floop's +answer_type enum is already the type signature. Six operators: + +- lookup: bind a relation with variables — position_held(sanchez, ?o, I) +- temporal filter: contains(I, now), end(I_x) ≤ start(I_s) — Allen as + computed views over extracted endpoints; +- order & selection: latest, max, nth (ranking questions); +- set ops: difference/intersection/count (the setop engine exists); +- arithmetic composition: typed templates over intervals (the Run T3 + composition: n_physical = n_logical × ratio); +- path: member_of, succeeded, same_as (multi-hop = chaining; the plan's + depends_on already encodes hops). + +Not full FOL — a conjunctive + temporal + algebraic fragment with +negation only as inequality. Typed: a term that type-checks against the +answer_type is valid before any evaluation; a mistranslation surfaces as +an invalid term, deterministically. The translator is one LLM call with +structured output (the MASK/EXTRACT class — typed, question-local, no +goal leakage), validated before execution. + +### Evaluation = proof = the answer object + +Goal-directed evaluation (SLD-style) over the store: + + q(x) :- position_held(sanchez, O, I_s), % his office, window + position_held(x, O, I_x), % any holder of the SAME office + x ≠ sanchez, + end(I_x) ≤ start(I_s), % term ended before his began + latest_by(end(I_x)) % the most recent such holder + +Leaves = edge ids (each carries quote + url); steps = one of the six +operators; checks = interval arithmetic. The proof term IS the payload: +re-execution over the store is the verification — deterministic, no +LLM. verified=True stops being the setop's generous flag and gets a +real prover; the stop-check becomes "does the goal have a closed path" +— the derivability check the _finish stub owes. + +### What the three findings become under this engine + +- Multi-binding IS the ambiguity: "of what is Sánchez president" as + position_held(sanchez, ?x, I), contains(I, now) returns THREE + bindings (Spain, PSOE, SI), deterministically, each with its proof. + The ablation audit becomes redundant for store-derivable rows; the + (K5) bug dies at the root — there is no judge to contaminate a value + and no single-value pressure. Branches map 1:1 to bindings. +- Silence is the failure mode: no closed path → UNKNOWN → the gather + runs. The judge's failure mode was a fluent wrong answer (SI with + confidence: high). +- The unbound variable IS the missing subquestion: when evaluation + stalls, the unligated variable names what to go fetch — MISSING + becomes semi-deterministic. +- Conflicts/alternatives become disjunction: each alternative pair is + an OR-node in the proof tree; evaluation branches per reading, + preferred picks the default reading, the question can force the + others. The polisèmia stops being an internal anomaly and becomes + semantic branching of the proof search. + +### Honest limits + +- Soft questions (why/compare/significance) are synthesis over many + rows, not queries: they stay LLM-composed — over proven components + (proof terms and leaves), not free prose over the store. +- The prover does not remove retrieval; it removes the judge inside + the loop. Facts absent from the store still need the gather. +- same_as/aliases are load-bearing: without the redirect-canonicalized + ontology, evaluation fails on vocabulary, not logic ("President of + the Government" vs "Prime Minister of Spain"). +- Cross-granularity comparison needs the year-as-interval convention + decided once, not per query. + +### Engine choice + +Hand-written goal-directed evaluator over SQLite first (six operators, +proof terms as objects, re-execution as check) — fixed code that +reasons, the house law. clingo earns its place if re-decomposition goes +declarative (answer sets = readings); Z3 earns it in FUNCTION +composition over intervals (Run T3 with certificates). Neither is a +dependency for v1 of this. + +## Verification plan (before any of this is mergeable) + +1. Taxonomy unit tests over the live 20-pair inventory as fixtures: + every pair lands in its measured bucket (10 co-asserted, 3+1 + temporal, 3 alternatives, 5 multi-valued co-true, 0 real). +2. Temporal: the "became" pair classified succession from quote-stated + dates; the three presidencies classified overlapping-open-intervals + → alternatives; no date invented anywhere (empty windows stay empty + until a source closes them). +3. Extractor restrictions: the month-duration/resignation sentence + yields concurrent + duration + event-anchored end with containment + checks passing; a date not in the quote is rejected. +4. Query engine: the Pedro question proves Rajoy as a closed path with + re-execution verifying; "of what" returns the three bindings as a + set; the rivers regression stays green; judge LLM calls per + knowledge question go to zero on store-derivable paths. +5. The K5 repro pair becomes the regression: raw glm-style judge values + never exist anymore on proven paths (nothing to clean — the + interface is gone, not patched). + +## What this does NOT touch + +- The gather, the skim, the LIST path, setop guard — unchanged. +- The ablation audit stays for the one job left to it: readings that + are NOT store-derivable (judge-visible ambiguity in free text). +- Branching (floop/branches.py) gains a cleaner trigger (a binding set) + but its death/merge semantics are untouched. \ No newline at end of file diff --git a/code/knowledge/RESEARCH-semantic-kg.md b/code/knowledge/RESEARCH-semantic-kg.md index 814e6bd..f12f79e 100644 --- a/code/knowledge/RESEARCH-semantic-kg.md +++ b/code/knowledge/RESEARCH-semantic-kg.md @@ -130,4 +130,83 @@ rows were never extracted". - The mask/ablation audit (dst-first law, run-L fix) — it gains signal. - Anonymization before INIT (PR-16/17) — orthogonal. - The branching design — still pending discussion; this branch may - feed it better questions, but does not implement it. \ No newline at end of file + feed it better questions, but does not implement it. + +## Findings from the live A/B and the (K5) bug (24–25/10, glm-5.3-flash) + +**The A/B he asked for** (his question, cold KG both sides, dspy disk +cache deleted per run): + +- glm-5.3-flash (cloud, cold KG): Rajoy, correct, 28 calls, 148 s. +- qwen3.8-27b (his PC via the house router, cold KG): honest UNKNOWN, + 33 calls, 3,025 s. The KG HELD Rajoy (K12 "Rajoy recommended Sánchez + as his successor") — the judge lost it to a noise row ("ninth + president of Socialist International" made it read "that specific + presidency" as the SI). +- Warm-KG glm answered "Sánchez himself" (the third-succeeded-second + reading trap). Substrate state weighs as much as the model. +- Cloud is non-deterministic at temperature 0: identical INIT prompt, + two different decompositions (2 vs 3 subquestions) across runs. +- MEASUREMENT TRAP (both A/B sides): dspy.LM defaults cache=True and + persists to ~/.dspy_cache ACROSS processes and days, keyed on the + request (model+prompt+params, not base_url). A repeated question is + a byte-identical REPLAY wearing inference's clothes (0.4 s "runs"). + Proven by curl (server does not cache) and by running the whole app + in an isolated netns (unshare -rn) — it completed with no network. + rm -rf ~/.dspy_cache before any run that must be fresh. + +**The (K5) bug — the audit's silent death** (run 085457): + +- glm answered Q1 ("which country or organization was he President + of?") with value="Socialist International (K5)" — the row-id glued + to the value, because AnswerFromKG says "cite rows by id" but has NO + citation output field. The judge sees K{i} ids (positional + enumerate indices over the probe's view — NOT store keys), so it + cites in the only field it has. +- _audit_ambiguity's _carries looks for the value inside row dsts: + "socialist international (k5)" is in no dst → support = [] → "the + judge invented it: nothing to ablate" → silent return. The audit + never runs. Repro on the warm KG: raw value → no audit; cleaned + value ("Socialist International") → ambiguous=True with Spain + alternatives (two rounds). The detector works; the interface kills + it. Value contamination is systematic with glm-5.3-flash, three + observed shapes: "(K5)" suffix, parenthetical reasoning ("2018 + (Pedro Sánchez has been Prime Minister … cited from rows K16 and + K30)"), and a DATE question answered "15 (list of 15 members: …)" + via the LIST path. +- SECOND violation: pred.value.strip() enters the evidence payload + untyped — "typed payloads, never LLM prose" broken at the same spot. +- FIX DIRECTION (agreed, not yet coded): clean at the judge's output + boundary (_answer_from_rows), regex-anchored to trailing + row-citation shapes only ( "(PSOE)" inside a name is legitimate and + must survive). + +**Run 090402 — the branch's own machinery, live and green:** + +- Semantic probe live via VPS-local nomic-embed-text (his PC was down; + the house router had cloud-failovered and ollama.com has NO + embeddings API — same model pulled locally, identical vectors, + tau=0.45 calibration holds). "+9/+11 edges the lexical probe missed" + on both subquestions; final Rajoy correct. +- 0 AMBIGUOUS is CORRECT for this run: INIT decomposed to 2 subqs + (term-start → predecessor) and never asked "of what", so no scalar + answer ever faced the three readings. The ambiguity needs either + the "of what" subquestion or the conflicts-table signal (below). +- INFRA PITFAL: the code venv carries an editable-install pth that + pins imports to MAIN's tree — a PYTHONPATH shim that imported + knowledge.expert silently resolved to main and ran main's pipeline + inside the branch worktree (run 085457 was main code with the + branch's config; its "compose -> queries" line is main's + deterministic composer). Always assert the resolved module path + when running branch code with the shared venv. + +**The conflicts inventory (20 pairs in the live KG, ZERO real +contradictions):** 10 same-quote "called for" (co-asserted +conjunction, one platform sentence split into 5 triples), 5 +cross-quote "called for" (a multi-valued relation), 3 "position held" +(THE THREE PRESIDENCIES, pairwise — the polisèmia sitting in the +store since ingest), 1 "became" (temporal: 2014 vs 2018 live in the +quotes, ref_date empty), 1 "re-elected as" (entity-diff PSOE/PM). +The taxonomy, the temporal representation, and the answer engine that +consumes all of this are designed in RESEARCH-derived-answers.md (this +branch, same session). \ No newline at end of file