feat(knowledge): real Wikipedia vertical with containment-checked KG

knowledge/: wiki.py (official MediaWiki API, own session+UA; fetch_rich appends wikitext tables as text - plain extracts drop them), chunker.py (section-aware, level paths), checks.py (verbatim containment, quote-aware), store.py (SQLite append-only, 4 contradiction cases, probe by entity AND relation with stemming), extract.py (dspy Signatures: TRANSLATE resolves pronouns from context and emits queries+entities, EXTRACT per chunk, ANSWER from KG rows), expert.py (the pipeline: KG-first probe -> gap -> translate -> search -> fetch_rich -> chunk -> gate -> extract -> check -> merge -> re-probe -> answer). Wiring: KnowledgeEngine in floop/engine.py (machine injects charge+modules at call time; baseline fallback on pipeline failure), machine routes knowledge questions to it, config.yaml knowledge: block. E2E verified live: Loire length answered from KG with zero network; the 2-hop EU-river question resolved France (population table row quote) -> Loire (KG hit) in 12 calls/75s. Six live-run bugs closed (wiki lib 403/HTML, dropped tables, pipes-in-quotes parse, gate stemming, relation probe, pronoun context). RUNLOG Run C added; code/README honest map updated. Tests 17/17.
This commit is contained in:
2026-10-16 23:19:09 +02:00
parent aecaac01eb
commit 9094b2aec0
15 changed files with 1111 additions and 13 deletions
+25 -1
View File
@@ -73,8 +73,32 @@ def main() -> None:
print(f"\nrun log: {streams.run_dir / 'run.log'}")
return
# knowledge expert: real pipeline when enabled, baseline LLM otherwise
knowledge_engine = None
if cfg.get("knowledge", {}).get("enabled", False):
try:
from knowledge.expert import KnowledgeExpert, KnowledgeConfig
from knowledge.store import KnowledgeStore
from floop.engine import KnowledgeEngine, LLMExpertEngine
kcfg = cfg["knowledge"]
kconfig = KnowledgeConfig(
kb_path=str(code_dir / kcfg.get("kb_path", "knowledge_store/kg.sqlite")),
max_articles=kcfg.get("max_articles", 2),
max_search_results=kcfg.get("max_search_results", 4),
max_chunks_extracted=kcfg.get("max_chunks_extracted", 6),
chunk_chars_target=kcfg.get("chunk_chars_target", 32000),
chunk_chars_cap=kcfg.get("chunk_chars_cap", 48000),
)
ke = KnowledgeExpert(config=kconfig, streams=streams)
knowledge_engine = KnowledgeEngine(ke)
streams.log(f"knowledge pipeline enabled (kb={kconfig.kb_path})")
except Exception as e: # noqa: BLE001 — degrade honestly, never die at startup
streams.log(f"knowledge pipeline disabled: {e}")
knowledge_engine = None
try:
report: RunReport = FloopRun(question, budget, streams=streams).run()
report: RunReport = FloopRun(question, budget, streams=streams,
knowledge_engine=knowledge_engine).run()
finally:
streams.close()