"""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, charge_llm=None): """Pass 2: ONE claim -> one typed Fact (or None, honestly declined). The Fact carries the verbatim quote and any temporal restrictions the text states; the store's containment checks validate everything downstream exactly as before. No orders: no siblings by construction. """ if charge_llm: charge_llm() pred = expert.typeclaim(claim=claim) return getattr(pred, "fact", None)