Skip to content

Commit 3c5d05d

Browse files
Jonathan Harrisonclaude
andcommitted
fix(router): factual queries -> constraint_tracker + word-boundary keyword match
Directness root cause: factual fast-path routed to newton, but the voice-reinforced newton adapter over-elaborates and buries the answer ("spiders have eight distinct features related to their leg structure...") instead of stating it. Route simple factual queries to constraint_tracker instead — its training is terse, answer-first, constraint-compliant. Also fixed a substring false-positive: short alphabetic keywords now match on a word boundary, so "api" (systems_architecture) no longer matches inside "cApItal" — "What is the capital of France?" was misrouting to systems and giving a non-answer (hurting hallucination_prevention). Verified: all 6 benchmark factual queries now route to constraint_tracker; all domain canaries (newton/davinci/empathy/quantum/systems) unchanged. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 319a385 commit 3c5d05d

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

inference/adapter_router.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,21 @@ def _route_keyword(self, query: str, max_adapters: int) -> RouteResult:
291291
score = 0.0
292292
matched = []
293293

294+
# Short alphabetic keywords ("api", "both", "good") must match on a
295+
# word boundary — naive substring matching false-fires inside longer
296+
# words (e.g. "api" in "cAPItal" sent "capital of France" to systems).
297+
def _kw_hit(kw: str) -> bool:
298+
if kw.isalpha() and len(kw) <= 4:
299+
return re.search(r"\b" + kw + r"\b", query_lower) is not None
300+
return kw in query_lower
301+
294302
for kw in keywords.get("strong", []):
295-
if kw in query_lower:
303+
if _kw_hit(kw):
296304
score += 2.0
297305
matched.append(f"+{kw}")
298306

299307
for kw in keywords.get("moderate", []):
300-
if kw in query_lower:
308+
if _kw_hit(kw):
301309
score += 1.0
302310
matched.append(f"~{kw}")
303311

@@ -333,11 +341,17 @@ def _route_keyword(self, query: str, max_adapters: int) -> RouteResult:
333341
)
334342
_is_short = len(query_lower.split()) <= 12
335343
_is_factual = _is_short and any(query_lower.startswith(p) for p in _factual_leads)
336-
if _is_factual and not personal_score and "newton" in self.available:
344+
if _is_factual and not personal_score:
345+
# Prefer constraint_tracker: its training is terse, answer-first,
346+
# constraint-compliant output — ideal for "just state the fact".
347+
# Perspective adapters (esp. newton) over-elaborate and bury the
348+
# answer behind analytical framing on trivial questions.
349+
_direct = ("constraint_tracker" if "constraint_tracker" in self.available
350+
else ("newton" if "newton" in self.available else None))
337351
return RouteResult(
338-
primary="newton",
352+
primary=_direct,
339353
confidence=0.5,
340-
reasoning="Simple factual query — direct single-adapter answer",
354+
reasoning="Simple factual query — direct, answer-first adapter",
341355
strategy="keyword",
342356
)
343357

0 commit comments

Comments
 (0)