machine: fan-out planner + disjointness guard (runs 07/08 lessons)
(a) Disjointness guard (knowledge/expert.py): a LIST ingest whose members
don't overlap the entities the parent's evidence names is refused; the
gather continues to the next article. Run-08's 'flow of Po/Adige/Tiber'
answered by the Amazon from a world-wide table can no longer happen.
(b) Fan-out planner (floop/machine.py): a 'for each' subquestion over a list
row expands deterministically into N entity questions + one join.
Top-N bound respected ('those three' over 22 rows -> top 3 by table
order, logged). The join is a deterministic sum over the entity rows
(verified=True: computation is its own proof), partial sums named.
Entity rows are tagged fan_group in provenance so the join finds them.
Also: LIST ingest keeps TABLE ORDER (ranked tables rank; alphabetical sort
destroyed the ranking) — dict.fromkeys dedup.
Budget: 40 -> 80 (a 3-entity fan-out needs ~3x a scalar question).
Verified live (cold KG, 2 runs): list ingest in table order, slice top-3,
fan-out -> 3 entity questions + join, Po answered with verbatim quote
(1,460 m3/s). 28/28 tests (fan-out expansion+join, top-N slice, guard).
This commit is contained in:
@@ -296,6 +296,34 @@ def test_list_ingest_aggregate(tmp="/tmp/floop_kg_list.sqlite"):
|
||||
print("ok test_list_ingest_aggregate")
|
||||
|
||||
|
||||
def test_disjoint_guard_refuses_wrong_list():
|
||||
"""The disjointness guard: an ingest whose members don't overlap the
|
||||
entities the parent's evidence names is refused; the gather continues.
|
||||
Emili's run-08: 'flow of Po, Adige, Tiber' must never be answered by the
|
||||
Amazon's flow from a world-wide discharge table."""
|
||||
from knowledge.expert import KnowledgeExpert, KnowledgeConfig
|
||||
|
||||
ke = KnowledgeExpert.__new__(KnowledgeExpert)
|
||||
ke.cfg = KnowledgeConfig()
|
||||
ke.streams = None
|
||||
ke._log = lambda text, think=False: None
|
||||
|
||||
# the parent's evidence: a scalar row naming the three rivers
|
||||
evidence = "E1: Po, Adige, Tiber (answers Q1)"
|
||||
assert ke._expected_entities(evidence) == ["Po", "Adige", "Tiber"]
|
||||
|
||||
# a world-wide discharge list: disjoint from the expected entities
|
||||
assert ke._guard_ingest({"list_items": ["Amazon", "Congo", "Yangtze"]}, evidence) is False
|
||||
# the right list: overlap — ingest is fine
|
||||
assert ke._guard_ingest({"list_items": ["Po", "Adige", "Tiber"]}, evidence) is True
|
||||
# no evidence (top-level question): guard passes, ingest is fine
|
||||
assert ke._guard_ingest({"list_items": ["Amazon", "Congo"]}, "") is True
|
||||
# LIST row evidence: 'list of 22 items: Po, Adige, ...' also seeds entities
|
||||
ev2 = "E1: list of 3 items: Po, Adige, Tiber (answers Q1)"
|
||||
assert ke._expected_entities(ev2) == ["Po", "Adige", "Tiber"]
|
||||
print("ok test_disjoint_guard_refuses_wrong_list")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_chunker_sections()
|
||||
test_containment()
|
||||
@@ -304,4 +332,5 @@ if __name__ == "__main__":
|
||||
test_verify_count()
|
||||
test_list_ingest_aggregate()
|
||||
test_table_parser_untruncated()
|
||||
print(f"\n{test_table_parser_untruncated.__name__} etc — 7 knowledge tests passed")
|
||||
test_disjoint_guard_refuses_wrong_list()
|
||||
print(f"\n{test_table_parser_untruncated.__name__} etc — 8 knowledge tests passed")
|
||||
Reference in New Issue
Block a user