feat: two-pass EXTRACT (claims -> typed Facts) for prose chunks
His diagnosis accepted (26/10): the single-pass EXTRACT's giant typed JSON array (verbatim quotes + temporal restrictions + sibling orders) is the output budget behind the 40-minute arithmetic on slow local models. Two-pass shortens EVERY output: - Pass 1 ExtractClaims: plain claim strings, coreferences resolved (entities named, never pronouns) — near-zero format tax. - Pass 2 TypeClaim: ONE claim -> one typed Fact per call (same Fact schema the store eats; temporal fields optional, containment-checked downstream as always). Orders NEVER produced here: one claim at a time has no siblings — the legacy Fact keeps orders for the single-pass path and table frags, untouched. - extract_mode: two_pass (default) | single (legacy) — config-driven, read from config.yaml's knowledge block by run_app. - Budget: Pass 1 charges once per chunk; Pass 2 charges once per claim. Table frags keep the legacy single-pass call. - Prompt log: CLAIMS/TYPE stage labels added. TDD: two_pass_extract 5/5 (signatures, coref law, honest empties) + two_pass_wiring 2/2 (end-to-end on a real store: two_pass ingests typed facts with windows kept; single-pass control green). Suite: 29 test files green. The router from #26 makes the upcoming extraction-model swap a pure config edit.
This commit is contained in:
@@ -30,12 +30,13 @@ from floop.llm import predict
|
||||
from .checks import check_candidate, quote_containment
|
||||
from .chunker import chunk_page
|
||||
from .skim import find_quantities, skim_article
|
||||
from .extract import (AnswerFromKG, ExtractSignature, Fact, SelectTableSignature,
|
||||
SkimPromoteSignature, SkimTableSignature,
|
||||
VerifyCountSignature)
|
||||
from .extract import (AnswerFromKG, ExtractClaims, ExtractSignature, Fact,
|
||||
SelectTableSignature, SkimPromoteSignature,
|
||||
SkimTableSignature, TypeClaim, VerifyCountSignature)
|
||||
from .embeddings import EmbedderDown, embed
|
||||
from .queries import compose_queries, keywords, proper_nouns
|
||||
from .store import KnowledgeStore, norm_name
|
||||
from .two_pass import claims_from, fact_from_claim
|
||||
from .wiki import (WikipediaClient, WikiPage, WikiTable, resolve_convert,
|
||||
tables_as_chunks, format_table_frag)
|
||||
|
||||
@@ -163,6 +164,9 @@ class KnowledgeConfig:
|
||||
semantic_tau: float = 0.45 # calibration: rivers 0.49-0.52 in, Pedro
|
||||
# cross-question 0.35-0.38 out, spouse-noise ~0.67
|
||||
max_facts_per_chunk: int = 12 # question-blind extraction needs a cap
|
||||
extract_mode: str = "two_pass" # "two_pass" (claims -> typed Facts, short
|
||||
# outputs) | "single" (legacy one-call typed
|
||||
# array — table frags keep using it)
|
||||
|
||||
|
||||
class KnowledgeExpert:
|
||||
@@ -176,6 +180,8 @@ class KnowledgeExpert:
|
||||
self.client = client or WikipediaClient()
|
||||
self.streams = streams
|
||||
self.extract = predict(ExtractSignature)
|
||||
self.claims = predict(ExtractClaims)
|
||||
self.typeclaim = predict(TypeClaim)
|
||||
self.answer = predict(AnswerFromKG)
|
||||
self.select_table = predict(SelectTableSignature)
|
||||
self.verify_count = predict(VerifyCountSignature)
|
||||
@@ -1166,6 +1172,21 @@ class KnowledgeExpert:
|
||||
think=True)
|
||||
extracted = 0
|
||||
for chunk in capped:
|
||||
if self.cfg.extract_mode == "two_pass":
|
||||
# two-pass (26/10): Pass 1 claims (short strings, coref
|
||||
# resolved), Pass 2 one typed Fact per claim — every
|
||||
# output short; the giant typed array is gone from prose.
|
||||
claims = claims_from(self, entities=ent_str,
|
||||
heading=chunk.heading_path,
|
||||
text=chunk.text, charge_llm=charge_llm)
|
||||
for claim in claims[: self.cfg.max_facts_per_chunk]:
|
||||
fact = fact_from_claim(self, claim, charge_llm=charge_llm)
|
||||
if fact is None:
|
||||
continue # honestly declined: no invention
|
||||
merged, _eid = self._ingest_candidate(
|
||||
fact, page, containment=page.text)
|
||||
extracted += merged
|
||||
continue
|
||||
if charge_llm:
|
||||
charge_llm()
|
||||
raw = self.extract(entities=ent_str, heading=chunk.heading_path,
|
||||
|
||||
Reference in New Issue
Block a user