store/expert/machine: keep source order end-to-end; refuse fake top-N

log-09 bug: a KG-served set answered the fan-out top-3 with adda, adige,
arno — the alphabetical list_members order masquerading as a ranking.

- edges.list_ord (auto-migrated): each member_of edge records its row
  position in the source table; list_members(ordered=True) returns source
  order, list_is_ordered() tells whether the set has proven order
- ingest writes ordinals; fresh-serve and _serve_set keep table order and
  set coverage.ranked accordingly
- fan-out top-N: slices ONLY ranked lists; an unranked list refuses the
  slice, expands all entities, and says so in notes + thinking (never
  silently alphabetical)
- regression test: Po/Adige/Tiber first; unordered set -> all expanded
This commit is contained in:
2026-10-19 20:31:04 +02:00
parent 2489ce3898
commit 06124a0198
5 changed files with 132 additions and 26 deletions
+36 -1
View File
@@ -213,7 +213,8 @@ def test_fanout_respects_top_n_slice():
row = EvidenceRow(
qid=qid, answer_type=AT.LIST,
payload={"value": "5", "list_items": ["Po", "Adige", "Tiber", "Reno", "Piave"],
"list_count": 5},
"list_count": 5,
"coverage": {"ranked": True}}, # real ingests declare order
engine="knowledge", trace=[], provenance={}, verified=False, note="")
if streams is not None:
streams.output("EXPERT", "value=5 (list, 5 items)")
@@ -228,6 +229,40 @@ def test_fanout_respects_top_n_slice():
finally:
M.LLMExpertEngine = _restore_llm_engine
# UNRANKED list + top-N ask: the slice is REFUSED — alphabetical trivia
# must never masquerade as a ranking (log-09: adda, adige, arno)
class UnrankedRowEngine:
def __init__(self, modules, charge, expert_kind):
self.charge = charge
def run(self, qid, question, parent_question, table, answer_type, streams=None):
from floop.state import AnswerType as AT, EvidenceRow
row = EvidenceRow(
qid=qid, answer_type=AT.LIST,
payload={"value": "5", "list_items": ["Adda", "Adige", "Arno", "Reno", "Piave"],
"list_count": 5}, # no coverage.ranked
engine="knowledge", trace=[], provenance={}, verified=False, note="")
if streams is not None:
streams.output("EXPERT", "value=5 (list, 5 items)")
return row
M.LLMExpertEngine = UnrankedRowEngine
try:
run2 = FloopRun("goal?", budget(), modules=FakeModules(
init_subs=[
{"text": "What are the longest rivers in Italy?",
"deps": [], "answer_type": "LIST"},
{"text": "What is the flow for each of those three rivers?",
"deps": [1], "answer_type": "CONSTANT"},
],
route_fn=lambda q: "knowledge", expert_value="100"))
rep2 = run2.run()
entity_qs2 = [q for q in run2.stack.items if q.reason.startswith("fan-out of")]
assert len(entity_qs2) == 5, "unranked: all entities, never a fake top-3"
assert any("REFUSED" in n for n in rep2.notes), rep2.notes
finally:
M.LLMExpertEngine = _restore_llm_engine
print("ok test_fanout_respects_top_n_slice")
# keep a handle to restore the real engine after monkeypatching
from floop.engine import LLMExpertEngine as _restore_llm_engine