feat: per-signature LM router (lm[<SigName>] config blocks + predict factory)

His ask: one general construction door so a signature's model/settings
change by editing config alone — no call-site ifs, now or ever after.
lm[ExtractSignature]: as a config.yaml sibling of lm: (provider:
inherits base_url + transport ceiling; model: builds a dedicated
cached LM; other keys -> per-call lm_kwargs through Predict config,
honored by dspy 3.4.1 _forward_preprocess). predict() is the door: the
13 construction sites swapped mechanically. First block shipped:
ExtractSignature max_tokens=1800 (the 4096 cap was 3x headroom that
only extended the worst case on slow local models — the 40-min
arithmetic). run.log reports active blocks at startup. TDD:
tests/lm_signature_router.py 5/5 (parse, no-block defaults,
settings-only override, dedicated+cached LM, provenance listing).
This commit is contained in:
2026-10-26 16:37:04 +01:00
parent 31c7e02e22
commit 6ba0bce863
6 changed files with 213 additions and 13 deletions
+8 -7
View File
@@ -25,6 +25,7 @@ import time
from dataclasses import dataclass
import dspy
from floop.llm import predict
from .checks import check_candidate, quote_containment
from .chunker import chunk_page
@@ -174,12 +175,12 @@ class KnowledgeExpert:
self.store = store or KnowledgeStore(self.cfg.kb_path)
self.client = client or WikipediaClient()
self.streams = streams
self.extract = dspy.Predict(ExtractSignature)
self.answer = dspy.Predict(AnswerFromKG)
self.select_table = dspy.Predict(SelectTableSignature)
self.verify_count = dspy.Predict(VerifyCountSignature)
self.skim_promote = dspy.Predict(SkimPromoteSignature)
self.skim_tables = dspy.Predict(SkimTableSignature)
self.extract = predict(ExtractSignature)
self.answer = predict(AnswerFromKG)
self.select_table = predict(SelectTableSignature)
self.verify_count = predict(VerifyCountSignature)
self.skim_promote = predict(SkimPromoteSignature)
self.skim_tables = predict(SkimTableSignature)
self._checked = 0
self._merged = 0
# semantic probe: cached question vector for this call (the probe
@@ -304,7 +305,7 @@ class KnowledgeExpert:
from .prover import evaluate, re_execute, validate_query
from .translate_dsl import TranslateToDSL
if not hasattr(self, "translate_dsl"):
self.translate_dsl = dspy.Predict(TranslateToDSL)
self.translate_dsl = predict(TranslateToDSL)
rels = [r[0] for r in self.store.db.execute(
"SELECT DISTINCT rel FROM edges WHERE retracted=0 "
"ORDER BY rel LIMIT 200").fetchall()]