Live cloud run 20261026-164236 found both on the wire:
1. TypeClaim carried ONLY the claim — the model could not copy the
verbatim quote from anywhere, so it invented one and the containment
check rejected 69/70 candidates (the safety net working, the
CONTRACT wrong). Fix: TypeClaim gains the chunk text; the model finds
the real quote there ('find the VERBATIM quote here, copied exactly').
2. One charge per claim starved the budget: ~70 claims ate all 80
llm_calls before Q2 (80/80, baseline fallback, no FINAL). Fix:
max_claims_per_chunk=6 (each claim costs a TYPE call; without a cap
one big article starves the run).
The speed win is real and kept: CLAIMS 14-20s/chunk, TYPE 2.8-8s/claim
(the 40-minute output budget is gone). Honest note: the cap bounds per
chunk, not the whole run (3 articles x 6 chunks x 7 calls ~ 126 > 80)
— if the run starves again, next lever is claim selection or a lower
cap, his call.
TDD: two_pass_extract 5/5 on the new contract (TypeClaim fields
{claim,text,fact}). Suite: 29 test files green.
42 lines
1.7 KiB
Python
42 lines
1.7 KiB
Python
"""The two-pass extraction (Pass 1 claims, Pass 2 typed Facts).
|
|
|
|
The single-pass EXTRACT asked slow local models for a giant JSON array
|
|
of typed Facts with verbatim quotes + temporal restrictions + sibling
|
|
order assertions — the output budget behind the 40-minute arithmetic.
|
|
Two-pass shortens every output: Pass 1 lists plain claims (free-form
|
|
strings, coreferences resolved — near-zero format tax); Pass 2 types
|
|
ONE claim at a time into the same Fact schema the store already eats.
|
|
|
|
Orders: NEVER produced here — one claim per call has no siblings to
|
|
reference. The legacy single-pass path (and table frags) keeps them.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
|
|
def claims_from(expert, entities: str, heading: str, text: str,
|
|
charge_llm=None) -> list[str]:
|
|
"""Pass 1: the chunk's claims as plain strings, coreferences resolved."""
|
|
if charge_llm:
|
|
charge_llm()
|
|
pred = expert.claims(entities=entities, heading=heading, text=text)
|
|
out = []
|
|
for c in (pred.claims or []):
|
|
c = (c or "").strip()
|
|
if c:
|
|
out.append(c)
|
|
return out
|
|
|
|
|
|
def fact_from_claim(expert, claim: str, text: str, charge_llm=None):
|
|
"""Pass 2: ONE claim -> one typed Fact (or None, honestly declined).
|
|
|
|
The Fact's quote is copied VERBATIM from `text` (the chunk the claim
|
|
came from) — without the text the model invents a quote and the
|
|
containment check rejects it (live finding 26/10: 69/70 rejected).
|
|
The store's checks validate everything downstream as before. No
|
|
orders: no siblings by construction.
|
|
"""
|
|
if charge_llm:
|
|
charge_llm()
|
|
pred = expert.typeclaim(claim=claim, text=text)
|
|
return getattr(pred, "fact", None) |