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
+7 -2
View File
@@ -48,6 +48,7 @@ Compare: `--baseline` vs the loop's many small directed calls.
| MISSING — gap decomposition on stuck goal | real (dspy) | `floop/dspy_modules.py` |
| ROUTE — one LLM judgement over the catalogue | real (dspy) | `floop/dspy_modules.py` |
| Expert attendants (the draft answer) | **BASELINE engine**: LLM answers from its weights; `verified=False`; source recorded (`model_weights`/`given_evidence`) | `floop/engine.py` |
| **knowledge** expert | **REAL pipeline** (2026-10-17): KG probe (entity+relation, stemmed) -> TRANSLATE (queries+entities from context) -> en.wikipedia search -> fetch_rich (text + wikitext tables) -> section chunks -> lexical gate -> EXTRACT (verbatim quotes) -> containment check -> merge (4 contradiction cases) -> answer from quoted rows. Fallback: baseline LLM on pipeline failure. | `knowledge/` + `floop/engine.py:KnowledgeEngine` |
| Arrival check (type check + contradiction) | **STUB**: only UNKNOWN refusal | `machine._append_checked` |
| Prover (stop condition, derivability) | **STUB**: question stack terminal | `machine._finish` |
| `user` expert | not wired — explicit failure row | `floop/engine.py` |
@@ -76,6 +77,10 @@ tests/state.py unit tests (no LLM)
1. Real check layer on expert arrival (well-formedness per expert kind) — the
#1 failure mode is misformalization; keep it BEFORE engines.
2. `knowledge` expert with real search + verbatim quotes (one vertical E2E).
2. ~~`knowledge` expert with real search + verbatim quotes~~ **DONE 2026-10-17**
(Wikipedia-only, en; DuckDuckGo + general web later).
3. Prover for the stop condition (clingo/Z3) — replaces the stub derivability.
4. Log every run (v2's router will eat these trajectories).
4. Log every run (v2's router will eat these trajectories).
5. Knowledge efficiency: the gather still spends extraction calls on tangential
articles (US river lists matched the "longest river" gate); tune gate/articles.
Also: KG dedupe of noisy entities from early runs (`the loire` vs `loire river`).