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:
@@ -15,11 +15,13 @@ class InitSignature(dspy.Signature):
|
||||
"""You are the INIT step of a reasoning machine. Using ONLY concepts literally
|
||||
present in the question plus a generic planning scaffold (number, method,
|
||||
machine, resources, dependencies), ask: what information or knowledge do I
|
||||
need to answer this? Write 1-4 open subquestions in dependency order."""
|
||||
need to answer this? Write 1-4 open subquestions in dependency order.
|
||||
Use answer_type LIST when the subquestion asks for an enumeration of
|
||||
things (which countries, what rivers, list all members...)."""
|
||||
question: str = dspy.InputField()
|
||||
subquestions: str = dspy.OutputField(
|
||||
desc="one subquestion per line, pipe-separated fields: "
|
||||
"text | depends_on (line numbers or 'none') | answer_type (OPEN|FUNCTION|INTERVAL|CONSTANT)"
|
||||
"text | depends_on (line numbers or 'none') | answer_type (OPEN|FUNCTION|INTERVAL|CONSTANT|LIST)"
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -118,7 +118,9 @@ class KnowledgeEngine:
|
||||
evidence = chr(10).join(ev_lines[:6])
|
||||
try:
|
||||
ans = self.ke.answer_question(question, parent_question=parent_question,
|
||||
evidence=evidence, charge_llm=charge)
|
||||
evidence=evidence, charge_llm=charge,
|
||||
answer_type=str(answer_type.value)
|
||||
if hasattr(answer_type, "value") else str(answer_type))
|
||||
except Exception as e: # noqa: BLE001 — fallback honesty: log, don't die
|
||||
if streams:
|
||||
streams.state(f"knowledge pipeline failed ({e}); baseline fallback")
|
||||
@@ -132,6 +134,11 @@ class KnowledgeEngine:
|
||||
payload["quote"] = ans["quote"]
|
||||
if ans.get("url"):
|
||||
payload["url"] = ans["url"]
|
||||
if ans.get("list_items") is not None:
|
||||
payload["list_items"] = ans["list_items"]
|
||||
payload["list_count"] = ans.get("list_count", len(ans["list_items"]))
|
||||
if ans.get("coverage"):
|
||||
payload["coverage"] = ans["coverage"]
|
||||
prov = {"expert": "knowledge", "source": src,
|
||||
"note": ("source-verified: verbatim containment in trusted doc"
|
||||
if ans.get("quote") else "no quote — unverified")}
|
||||
|
||||
@@ -19,6 +19,7 @@ class AnswerType(str, Enum):
|
||||
FUNCTION = "FUNCTION"
|
||||
INTERVAL = "INTERVAL"
|
||||
CONSTANT = "CONSTANT"
|
||||
LIST = "LIST"
|
||||
|
||||
|
||||
class BudgetExhausted(Exception):
|
||||
|
||||
Reference in New Issue
Block a user