knowledge: answer-level count corroboration (DESIGN §12) — LIST rows verified via prose
- VerifyCountSignature: LLM finds ONE verbatim sentence in the article prose (tables excluded by construction) stating the set's count - _verify_count: code checks containment + digit equality — no LLM compares numbers; NOQUOTE -> count_corroborated=false (honest, one call, never loops) - row verified <=> complete_per_source AND count_corroborated - DESIGN §12 documents now vs deferred (extension, criteria, cross-article) - live: EU question cold — E1 (50) + E2 (27) both corroborated with quotes, 23 computed; 25/25 tests
This commit is contained in:
@@ -126,6 +126,58 @@ def test_migration_old_store():
|
||||
print("ok test_migration_old_store")
|
||||
|
||||
|
||||
def test_verify_count():
|
||||
"""Answer-level CHECK: the LLM finds a corroborating sentence, code
|
||||
compares the digits. Containment + equal digits -> corroborated."""
|
||||
from knowledge.expert import KnowledgeExpert, KnowledgeConfig
|
||||
from knowledge.extract import VerifyCountSignature # noqa: F401 — wiring proof
|
||||
|
||||
class FakeVerifier:
|
||||
def __init__(self, *a, **k):
|
||||
pass
|
||||
def __call__(self, **kw):
|
||||
class P: pass
|
||||
p = P()
|
||||
p.quote = ("The European Union (EU) is a supranational union of "
|
||||
"27 member states that are party to the EU's founding treaties")
|
||||
return p
|
||||
|
||||
class FakeNoVerifier:
|
||||
def __init__(self, *a, **k):
|
||||
pass
|
||||
def __call__(self, **kw):
|
||||
class P: pass
|
||||
p = P()
|
||||
p.quote = "NOQUOTE"
|
||||
return p
|
||||
|
||||
ke = KnowledgeExpert.__new__(KnowledgeExpert)
|
||||
ke.cfg = KnowledgeConfig()
|
||||
ke.streams = None
|
||||
ke.verify_count = FakeVerifier()
|
||||
prose = ("The European Union (EU) is a supranational union of 27 member "
|
||||
"states that are party to the EU's founding treaties, and thereby "
|
||||
"subject to EU law.")
|
||||
res = ke._verify_count("European Union member states", 27, prose, None)
|
||||
assert res is not None and res["count_corroborated"] is True
|
||||
|
||||
ke.verify_count = FakeNoVerifier()
|
||||
assert ke._verify_count("European Union member states", 27, prose, None) is None
|
||||
|
||||
# digits disagree -> not corroborated, honest
|
||||
class FakeWrongVerifier:
|
||||
def __init__(self, *a, **k):
|
||||
pass
|
||||
def __call__(self, **kw):
|
||||
class P: pass
|
||||
p = P()
|
||||
p.quote = "The European Higher Education Area includes 48 countries"
|
||||
return p
|
||||
ke.verify_count = FakeWrongVerifier()
|
||||
assert ke._verify_count("European Union member states", 27, prose, None) is None
|
||||
print("ok test_verify_count")
|
||||
|
||||
|
||||
def test_table_parser_untruncated():
|
||||
from knowledge.wiki import parse_tables
|
||||
# vertical layout, 5 rows, header row -> total_rows MUST be 5, no truncation
|
||||
@@ -202,6 +254,16 @@ def test_list_ingest_aggregate(tmp="/tmp/floop_kg_list.sqlite"):
|
||||
ke._merged = 0
|
||||
ke._log = lambda text, think=False: None # bound-style: no self
|
||||
|
||||
class FakeNoVerifier: # honest: no corroboration
|
||||
def __init__(self, *a, **k):
|
||||
pass
|
||||
def __call__(self, **kw):
|
||||
class P: pass
|
||||
p = P()
|
||||
p.quote = "NOQUOTE"
|
||||
return p
|
||||
ke.verify_count = FakeNoVerifier()
|
||||
|
||||
from knowledge.wiki import WikiPage
|
||||
page = WikiPage(title="List of states", pageid=1, url="u",
|
||||
fetched_at="2026-10-18T00:00:00+00:00", text="x",
|
||||
@@ -239,6 +301,7 @@ if __name__ == "__main__":
|
||||
test_containment()
|
||||
test_store_four_cases()
|
||||
test_migration_old_store()
|
||||
test_verify_count()
|
||||
test_list_ingest_aggregate()
|
||||
test_table_parser_untruncated()
|
||||
print(f"\n{test_table_parser_untruncated.__name__} etc — 6 knowledge tests passed")
|
||||
print(f"\n{test_table_parser_untruncated.__name__} etc — 7 knowledge tests passed")
|
||||
Reference in New Issue
Block a user