TypeClaim does not need to rewrite the quote/verbatim

This commit is contained in:
2026-11-01 17:12:32 +01:00
parent 4e7229c92c
commit 3d541ec8d6
5 changed files with 112 additions and 88 deletions
+44 -35
View File
@@ -5,31 +5,34 @@ temporal fields + sibling order assertions in ONE giant JSON array — the
output budget that produced the 40-minute arithmetic. The two-pass split
shortens EVERY output: Pass 1 extracts the claims, each with its
VERBATIM quote (coreference resolved to the entity names); Pass 2 types
ONE claim into the existing Fact schema per call — typing ONLY, the
verbatim given to it as an input (owner 1/11: the VERBATIM is obtained
before; the TYPE call never sees the text).
ONE claim per call — TYPING only, the model sees ONLY the claim and
returns FactNoQuote; code composes the Fact: FactNoQuote + verbatim
(owner 1/11: the VERBATIM is obtained before, the TYPE model never sees
nor rewrites it).
CRITICAL law: Pass 2 works on ONE CLAIM AT A TIME — sibling order
assertions become IMPOSSIBLE by construction, so orders are dropped from
the two-pass path (the store's fact_order keeps working for whatever
arrives as a typed Fact with orders; the two-pass facts carry none).
The store, the containment checks and the merge are UNTOUCHED — Pass 2
emits the same typed Fact as before, minus orders.
CRITICAL law: Pass 2 works on ONE CLAIM AT A TIME — the TYPE schema
(FactNoQuote) has NO orders field at all, so sibling order assertions
are impossible by construction (the store's fact_order keeps working
for whatever arrives as a typed Fact with orders; the two-pass facts
carry none). The store, the containment checks and the merge are
UNTOUCHED — the composed Fact is the same typed Fact as before, minus
orders.
Pinned:
1. ExtractClaims: free-form claims, coreferences RESOLVED (the claim
must name its entities, not 'he/it/the party'), each carrying its
VERBATIM quote — the quote is extracted HERE, in Pass 1.
2. TypeClaim: one claim + its verbatim in -> one typed Fact out (same
fields as the legacy ExtractSignature.facts minus orders; temporal
fields optional) — no text input: the VERBATIM enters as an input.
3. The pipeline wiring: the two-pass path returns typed Fact objects;
candidates flow into _ingest_candidate exactly as before.
2. TypeClaim: one claim in -> one FactNoQuote out (Fact minus quote,
minus orders; temporal fields optional) — no text, no verbatim
input: the TYPE model never sees the quote.
3. The pipeline wiring: the two-pass path returns composed Fact
objects; candidates flow into _ingest_candidate exactly as before.
4. Honest empty: no claims -> no facts, no invention.
5. The legacy single-pass signature STAYS (table frags use it; flipping
the whole pipeline over is a later decision, config-driven).
6. Code PINS the Fact's quote to Pass 1's verbatim (LLMs propose, code
decides) — the TYPE model cannot corrupt the span.
6. Code COMPOSES the output Fact = FactNoQuote + verbatim (LLMs
propose, code decides) — the TYPE model never sees nor rewrites
the quote, so it cannot corrupt the span.
Run: .venv/bin/python knowledge/tests/two_pass_extract.py
"""
@@ -43,7 +46,7 @@ sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
sys.path.insert(0, str(Path(__file__).resolve().parent.parent.parent))
from knowledge.extract import (Claim, ExtractClaims, ExtractSignature, Fact,
TypeClaim)
FactNoQuote, TypeClaim)
from knowledge.two_pass import claims_from, fact_from_claim
@@ -70,22 +73,25 @@ def test_extract_claims_signature():
def test_type_claim_signature():
"""Pass 2: one claim + its verbatim -> one typed Fact; no text input;
orders NEVER produced here."""
"""Pass 2: one claim -> one typed FactNoQuote; no verbatim, no text;
orders IMPOSSIBLE (no orders field at all)."""
fields = set(TypeClaim.__fields__)
# the VERBATIM is obtained BEFORE (Pass 1) and enters as an input; the
# text is GONE — the quote-finding job moved to ExtractClaims (owner
# 1/11: TypeClaim only enforces the correct typing of the Fact).
assert fields == {"claim", "verbatim", "fact"}, fields
# the model sees ONLY the claim: the VERBATIM (Pass 1's) is NOT an
# input — nothing to copy, nothing to rewrite (owner 1/11).
assert fields == {"claim", "fact"}, fields
f = TypeClaim.model_fields["fact"].annotation
assert "Fact" in str(f), f
# Fact KEEPS orders (the legacy single-pass path and table frags use
# them — untouched); the two-pass law is that TypeClaim never fills
# them: one claim per call means no siblings to reference.
assert "orders" in Fact.model_fields, "legacy Fact must keep orders"
assert "FactNoQuote" in str(f), f
# FactNoQuote: Fact minus quote (never shown to the TYPE model)
# minus orders (one claim per call: no siblings to reference — the
# two-pass law, now enforced by the SCHEMA itself)
assert "quote" not in FactNoQuote.model_fields, "FactNoQuote must not carry a quote"
assert "orders" not in FactNoQuote.model_fields, "one claim per call: no siblings to reference"
# Fact KEEPS quote + orders (the legacy single-pass path and table
# frags use them — untouched)
assert "quote" in Fact.model_fields and "orders" in Fact.model_fields
d = TypeClaim.__doc__ or ""
assert "one claim" in d.lower() or "single" in d.lower(), d
print("ok: TypeClaim = one claim + verbatim in -> one Fact (typing only; no text)")
print("ok: TypeClaim = one claim -> FactNoQuote (typing only; no quote, no orders)")
def test_claims_from_runs_pass1():
@@ -104,18 +110,21 @@ def test_claims_from_runs_pass1():
def test_fact_from_claim_types_one_fact():
"""Pass 2 types one claim; CODE pins the Fact's quote to the given
verbatim — the scripted fact proposes a paraphrase, and it MUST be
overwritten (LLMs propose, code decides)."""
e = Scripted(typeclaim=Scripted(fact=Fact(
"""Pass 2 types one claim; code COMPOSES the Fact = FactNoQuote +
verbatim — the scripted FactNoQuote has no quote to invent, and the
returned Fact carries Pass 1's verbatim (LLMs propose, code
decides)."""
e = Scripted(typeclaim=Scripted(fact=FactNoQuote(
subject="Pedro Sanchez", relation="prime minister of",
object="Spain", quote="a paraphrase the TYPE model invented",
object="Spain",
start="2018", end=None, point=None, granularity="year")))
f = fact_from_claim(e, claim="Pedro Sanchez is the prime minister of Spain since 2018",
verbatim="has been the prime minister of Spain since 2018")
assert f.subject == "Pedro Sanchez" and f.start == "2018", f
assert f.quote == "has been the prime minister of Spain since 2018", f.quote
print("ok: fact_from_claim types one claim; code pins quote to the verbatim")
assert isinstance(f, Fact), f # the store eats a real Fact
assert f.orders == [], f.orders # composed default: no siblings
print("ok: fact_from_claim composes Fact = FactNoQuote + verbatim")
def test_honest_empty():