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
+15 -10
View File
@@ -182,12 +182,14 @@ class RoomMap:
# ── Lookup Methods ────────────────────────────────────────────────
def find_room_by_keywords(self, text: str, min_score: int = 2, origin_room_id: Optional[str] = None) -> Optional[RoomEntry]:
def find_room_by_keywords(self, text: str, min_score: int = 1, origin_room_id: Optional[str] = None) -> Optional[RoomEntry]:
"""Find the room with the most keyword matches for *text*.
Args:
text: The message text to classify.
min_score: Minimum score required to return a room (default: 2).
min_score: Minimum score required to return a room (default: 1).
V8.4.6: Gesenkt von 2 auf 1 — ein einzelnes Kontext-Keyword
reicht für einen Butler-Vorschlag.
origin_room_id: Optional room ID of the message origin for priority matching.
Returns:
@@ -199,6 +201,8 @@ class RoomMap:
# Stufe 1: Prüfe 100% Evidenz Keywords zuerst
# Bei mehreren Räumen mit 100%-Matches: den mit den MEISTEN Treffern nehmen
# Catch-All-Räume werden in Stufe 1 NICHT berücksichtigt
# (100%-Keywords auf Catch-All sind für Auto-Route gedacht, nicht für Keyword-Match)
best_100_room: Optional[RoomEntry] = None
best_100_score: int = 0
@@ -218,22 +222,23 @@ class RoomMap:
# Stufe 2: Origin-Priorität mit kontextabhängigen Keywords
# Origin-Priorität gilt NUR für context-Keywords (100% schlagen immer durch)
# V8.4.6: Catch-All-Räume sind in Stufe 2 als Butler-Ziele erlaubt
if origin_room_id is not None and origin_room_id in self._rooms:
origin_room = self._rooms[origin_room_id]
if not origin_room.catch_all:
# Prüfe kontextabhängige Keywords im Ursprungsraum
context_score = sum(1 for kw in origin_room.keywords_context if kw.lower() in text_lower)
if context_score >= min_score:
return origin_room
# Prüfe kontextabhängige Keywords im Ursprungsraum
# (auch Catch-All-Räume — sie können Kontext-Keywords haben)
context_score = sum(1 for kw in origin_room.keywords_context if kw.lower() in text_lower)
if context_score >= min_score:
return origin_room
# Stufe 3: Globaler Scan mit kontextabhängigen Keywords
# V8.4.6: Catch-All-Räume sind in Stufe 3 als Butler-Ziele erlaubt.
# Catch-All als Keyword-Match-Ziel war für 100%-Auto-Route blockiert (Stufe 1).
# Für Kontext-Keywords (Stufe 3) sind Catch-All-Räume valide Butler-Ziele.
best_room: Optional[RoomEntry] = None
best_score: int = 0
for room in self._rooms.values():
if room.catch_all:
continue # Catch-All never matches keywords
# Prüfe kontextabhängige Keywords
context_score = sum(1 for kw in room.keywords_context if kw.lower() in text_lower)
if context_score > best_score: