"""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. The list is made honest by CODE only: exact repeats are dropped (live finding 26/10: glm sometimes lists its whole list twice, and thinking leakage leaks in as list items). Dedup is case- and whitespace-insensitive; the FIRST occurrence's exact text is kept. NO cap, NO semantic filter: completeness beats budget (owner ruling 26/10) — every unique claim gets its TYPE call. """ if charge_llm: charge_llm() pred = expert.claims(entities=entities, heading=heading, text=text) seen: dict[str, str] = {} for c in (pred.claims or []): c = (c or "").strip() if c: key = " ".join(c.lower().split()) if key not in seen: seen[key] = c return list(seen.values()) 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)