fix: V8.4.6 — FAISS schließt Ursprungsraum aus + Kontext-Keyword bei Catch-Butler (P0-Bundle)

Problem 1 (P0): Kontext-Keywords bei Catch-All-Räumen
- 'dji' ist ein Kontext-Keyword für DM (catch_all=True), aber Catch-All-Räume
  wurden von der Keyword-Match-Logik komplett ausgeschlossen.
- Fix: room_map.py find_room_by_keywords() erlaubt Catch-All-Räume in Stufe 2+3
  (Kontext-Keywords) als Butler-Ziele. Stufe 1 (100%-Keywords) schließt
  Catch-All weiterhin aus — 100%-Match auf Catch-All ist für Auto-Route,
  nicht für Keyword-Match.
- min_score von 2 auf 1 gesenkt: ein einzelnes Kontext-Keyword reicht für
  einen Butler-Vorschlag.

Problem 2 (P0): FAISS schließt Ursprungsraum nicht aus
- FAISS fand den Ursprungsraum als ähnlichsten Raum (score=0.62,
  target=#RC-Plugin, origin=#RC-Plugin). Sinnlos — Butler kann keinen
  Wechsel von #RC-Plugin → #RC-Plugin vorschlagen.
- Fix: router.py filtert origin_room_id aus FAISS-Ergebnissen heraus.
  Wenn alle Treffer der Ursprungsraum waren → fall-through zu LLM.
  Wenn top-1 excluded wird → top-2 wird verwendet.

Tests: 14 neue Tests in test_v8_4_6.py
- test_faiss_excludes_origin (2 Tests)
- test_faiss_butler_self_match (2 Tests)
- test_context_keyword_min_score_1 (3 Tests)
- test_context_keyword_catch_all (3 Tests)
- Regression (4 Tests)

Aktualisierte Tests:
- test_room_map.py: test_context_keywords_min_score → min_score=1
- test_v8_4_5.py: test_sony_context_keyword_triggers_butler → erwartet Butler

Full suite: 626 passed, 2 skipped, 0 failures
This commit is contained in:
Bernd (Hermes)
2026-07-16 10:37:42 +02:00
parent da5586e776
commit 463e29d594
5 changed files with 592 additions and 110 deletions
+88 -84
View File
@@ -677,98 +677,102 @@ class BidirectionalRouter:
text, k=FAISS_TOP_K, min_score=FAISS_MIN_SCORE
)
if faiss_hits:
# ── Keyword-Booster anwenden ──────────────────────
boosted = faiss_hits
booster_applied = False
if self._booster is not None:
# Boosten immer anwenden, nicht nur bei Konflikten
boosted = self._booster.boost(text, faiss_hits)
booster_applied = True
# ── V8.4.6: Ursprungsraum aus FAISS-Ergebnissen ausschließen ─
# FAISS findet oft den Ursprungsraum als ähnlichsten Raum
# (z.B. score=0.62, target=#RC-Plugin, origin=#RC-Plugin).
# Das ist sinnlos — Butler kann keinen Wechsel von
# #RC-Plugin → #RC-Plugin vorschlagen.
faiss_hits = [
(rid, score) for rid, score in faiss_hits
if rid != origin_room_id
]
if not faiss_hits:
# Alle FAISS-Treffer waren der Ursprungsraum → fall-through
logger.debug(
"FAISS Booster applied: always active",
"FAISS Phase-1: all hits were origin room %s → fall-through to LLM",
origin_room_id[:8] if origin_room_id else "DM",
)
routing_counter.increment('faiss_origin_excluded')
else:
# ── Keyword-Booster anwenden ──────────────────────
boosted = faiss_hits
booster_applied = False
if self._booster is not None:
# Boosten immer anwenden, nicht nur bei Konflikten
boosted = self._booster.boost(text, faiss_hits)
booster_applied = True
logger.debug(
"FAISS Booster applied: always active",
)
top_room_id, top_score = boosted[0]
top_room_id, top_score = boosted[0]
# ── Auto-Route bei hohem Score ────────────────────
if top_score >= FAISS_AUTO_ROUTE:
room = self._room_map.get_room_by_id(top_room_id)
if room is not None:
# Self-Match-Schutz: FAISS matched origin room
if top_room_id == origin_room_id:
logger.debug(
"FAISS self-match: '%s' matched origin room %s → stay_in_room",
text[:80], room.name,
# ── Auto-Route bei hohem Score ────────────────────
if top_score >= FAISS_AUTO_ROUTE:
room = self._room_map.get_room_by_id(top_room_id)
if room is not None:
room_name = (
room.name.replace("#", "")
if room.name.startswith("#")
else room.name
)
notification = f"📋 Bearbeite ich in #{room_name} — [Link]"
matched_keywords = self._extract_matched_keywords(text, room)
# ── P0-B: never_route topic check ──────────
if self._check_never_route_topic(origin_room_id, room):
return RoutingDecision(
category="direct_question",
target_room="",
confidence=1.0,
stay_in_room=True,
)
logger.info(
"FAISS Phase-1: auto-route '%s' → %s (score=%.3f, booster=%s)",
text[:80],
room.name,
top_score,
booster_applied,
)
routing_counter.increment('faiss_auto_route')
routing_telemetry.record(
stage='faiss', score=top_score, decision='route',
target=top_room_id, origin=origin_room_id,
duration_ms=routing_telemetry.elapsed_ms(),
)
logger.info("ROUTING DECISION: reason=faiss_auto_route, origin_room=%s, target_room=%s, stay=False, butler_mode=False", origin_room_id, top_room_id)
return RoutingDecision(
category="direct_question",
target_room="",
confidence=0.0,
stay_in_room=True,
category="work_order",
target_room=top_room_id,
confidence=top_score,
matched_room_name=room.name,
source_room_notification=notification,
matched_keywords=matched_keywords,
faiss_score=top_score,
faiss_room_id=top_room_id,
faiss_room_name=room.name,
is_faiss_routed=True,
booster_applied=booster_applied,
move_request_sent=False, # FIX D: FAISS-Auto-Route → kein Butler
move_request_target_name=room.name,
move_request_target_id=top_room_id,
)
room_name = (
room.name.replace("#", "")
if room.name.startswith("#")
else room.name
)
notification = f"📋 Bearbeite ich in #{room_name} — [Link]"
matched_keywords = self._extract_matched_keywords(text, room)
# ── P0-B: never_route topic check ──────────
if self._check_never_route_topic(origin_room_id, room):
return RoutingDecision(
category="direct_question",
target_room="",
confidence=1.0,
stay_in_room=True,
)
logger.info(
"FAISS Phase-1: auto-route '%s' → %s (score=%.3f, booster=%s)",
text[:80],
room.name,
top_score,
booster_applied,
)
routing_counter.increment('faiss_auto_route')
routing_telemetry.record(
stage='faiss', score=top_score, decision='route',
target=top_room_id, origin=origin_room_id,
duration_ms=routing_telemetry.elapsed_ms(),
)
logger.info("ROUTING DECISION: reason=faiss_auto_route, origin_room=%s, target_room=%s, stay=False, butler_mode=False", origin_room_id, top_room_id)
return RoutingDecision(
category="work_order",
target_room=top_room_id,
confidence=top_score,
matched_room_name=room.name,
source_room_notification=notification,
matched_keywords=matched_keywords,
faiss_score=top_score,
faiss_room_id=top_room_id,
faiss_room_name=room.name,
is_faiss_routed=True,
booster_applied=booster_applied,
move_request_sent=False, # FIX D: FAISS-Auto-Route → kein Butler
move_request_target_name=room.name,
move_request_target_id=top_room_id,
)
# ── Score unter Schwelle → Fall-through zu Embedding + LLM
logger.debug(
"FAISS Phase-1: top score %.3f < %.3f — fall-through to LLM",
top_score,
FAISS_AUTO_ROUTE,
)
routing_counter.increment('faiss_butler')
routing_telemetry.record(
stage='faiss', score=top_score, decision='butler',
target=top_room_id, origin=origin_room_id,
duration_ms=routing_telemetry.elapsed_ms(),
)
logger.info("ROUTING DECISION: reason=faiss_butler, origin_room=%s, target_room=%s, stay=False, butler_mode=True", origin_room_id, top_room_id)
# ── Score unter Schwelle → Fall-through zu Embedding + LLM
logger.debug(
"FAISS Phase-1: top score %.3f < %.3f — fall-through to LLM",
top_score,
FAISS_AUTO_ROUTE,
)
routing_counter.increment('faiss_butler')
routing_telemetry.record(
stage='faiss', score=top_score, decision='butler',
target=top_room_id, origin=origin_room_id,
duration_ms=routing_telemetry.elapsed_ms(),
)
logger.info("ROUTING DECISION: reason=faiss_butler, origin_room=%s, target_room=%s, stay=False, butler_mode=True", origin_room_id, top_room_id)
# ── Schritt 4: Embedding-Vorfilter (binär) ────────────────────
# Nur noch binär: "Smalltalk" vs. "potenzieller Auftrag"