# 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. ## Implementation plan (proposed — awaiting his approval; no code yet) Phases ordered by dependency; each closes with tests + live runs. Phase 0 is main-bound and independent of the research direction. ### Phase 0 — hygiene (main; small, shippable alone) 1. (K5) fix: clean the judge's value at the output boundary (_answer_from_rows) — regex anchored to TRAILING row-citation shapes ("(K5)", "(cited from rows K16 and K30)") so legitimate parentheticals ("(PSOE)") survive. Prompt side: value desc gains "answer only, no row citations". Regression = the K5 repro pair (raw value → audit runs and flags the Spain alternative). 2. --no-cache CLI flag (his ruling 25/10: the dspy disk cache is not a bug; it stays the default): when set, configure_lm builds dspy.LM with cache=False — a per-process bypass, the cache dir untouched. For A/B and freshness testing. 3. Import assert at startup: the resolved floop/ and knowledge/ module paths must be under the repo being run — the shared venv's editable pth pins imports to MAIN's tree and ran main code inside the branch worktree without any signal (run 085457). Abort loudly on mismatch. ### Phase 1 — conflict taxonomy at merge (this branch, store) _classify 4 → 6 cases, signals in cost order: same quote_id → co-asserted (conjunction, never a conflict); extracted windows → temporal (interval arithmetic: disjoint = succession, overlapping = alternatives); discriminant tokens + tail resolution against nodes → alternatives vs paraphrase-merge (merge = same_as edge, append-only); what survives with a functional relation = real contradiction. The edge gains a class field; the alternatives bucket is exposed to the audit and the render. Fixtures: the live 20-pair inventory (10 co-asserted, 3+1 temporal, 3 alternatives, 0 real). ### Phase 2 — temporal layer (this branch, extractor + store) Typed Fact (feature/typed-facts vehicle) gains start/end/point/ granularity, orders [{before|after|concurrent, refs}], duration, anchor (date | event node), immediacy — every field containment- checked against the quote. Store: edge start/end columns + fact_order table. _classify consumes interval arithmetic. Bounded backfill: re-extract quotes of existing conflicting pairs with empty windows. NO Allen labels anywhere — the algebra stays a computed view. ### Phase 3 — the query prover (the new core) Hand-written goal-directed evaluator over SQLite: six operators (lookup, temporal filter, order/select, setops, arithmetic composition, path), typed DSL, proof term as the payload, re-execution as the check. Translator question→DSL: one structured-output LLM call (MASK/EXTRACT class), validated before execution. Wiring: the prover becomes the real stop-check at machine._finish (derivability); AnswerFromKG stays only as the fallback for non-translatable questions. Regression: Pedro proves Rajoy as a closed path; "of what" returns the three bindings as a set; rivers stay green; judge LLM calls drop to zero on store-derivable paths. ### Phase 4 — consumers The audit reduces to "is the binding set already multi?" (cheap, deterministic) + ablation only for non-derivable readings. The branch fork (floop/branches.py) starts from binding multiplicity. ANSWER and any surviving judge render over proof terms, not free prose. ### Open decisions (his call, before Phase 3 coding) - DSL vocabulary: the translator and the evaluator share one grammar — its exact terms. - Order primitives: inside Fact (same call) vs a separate pass. - Translator location: inside INIT (the decomposition and the query born together) vs a post-INIT step per question.