feat(knowledge): LIST answer path — full table ingestion, typed list payloads

Part 1 of the lists design (DESIGN.md §11): mechanical full ingestion, separated from epistemic answer-completeness. parse_tables rewritten as a GRID parser: cells accumulate until |- (both layouts), empty cells kept as placeholders (image cells clean to ''; dropping them shifted France rows to start at 'FRA'), rowspan/colspan expanded at placement, total_rows is the computed extent — no truncation. _clean_cell: refs/sup/File links dropped, citation templates (cref2/efn...) resolve empty, links take display text, attrs split first. LIST path in expert.py: deterministic enumeration detection OR planner-declared LIST; SELECT TABLE (one LLM call over table metadata, never rows); ingest ALL rows as member_of edges (quote = full row line, containment against stored table text); aggregate via len() — no LLM. AnswerType.LIST added; evidence payloads carry list_items + coverage. Verified live cold: 50 sovereign states from the Europe article table (51 rows - Total footer), every member with verbatim quote. 19/19 tests.
This commit is contained in:
2026-10-18 16:53:10 +02:00
parent a78f65de2c
commit 6fcb3c0a86
9 changed files with 480 additions and 40 deletions
+19
View File
@@ -240,5 +240,24 @@ class KnowledgeStore:
ref_date=rd, corroboration=cor, preferred=bool(pref),
conflict=bool(conflict)))
# ---- membership queries (LIST path) --------------------------------------
def member_sets(self) -> list[str]:
"""Distinct set names that have membership edges (rel='member_of')."""
rows = self.db.execute(
"SELECT DISTINCT dst_value FROM edges WHERE rel='member_of' AND retracted=0"
).fetchall()
return [r[0] for r in rows]
def list_members(self, set_name: str) -> list[str]:
"""ALL elements of a set: every member_of edge pointing at set_name.
Deterministic and COMPLETE with respect to what was ingested (the
ingestion writes one edge per table row, untruncated)."""
rows = self.db.execute(
"SELECT DISTINCT n.norm_name FROM edges e "
"JOIN nodes n ON n.id=e.src_node "
"WHERE e.rel='member_of' AND e.retracted=0 AND lower(e.dst_value)=lower(?)",
(set_name,)).fetchall()
return sorted(r[0] for r in rows)
def close(self) -> None:
self.db.close()