Files
Hermes_rocket.chat_Plugin/scripts/smoke_test_booster.py
Bernd (Hermes) 374e2e7700 P-028 Mitigation: split keyword matching — match_keyword_exact for kw100, match_keyword for kwctx
TEIL 1 — booster.py:
- Split _keyword_to_rooms into _kw100_to_rooms + _kwctx_to_rooms
- keywords_100 matched via match_keyword_exact (no fuzzy/stemming, hyphen-insensitive)
- keywords_context matched via match_keyword (fuzzy/stemming preserved)
- _build_mapping() builds both mappings separately
- boost() uses separate matchers per keyword type
- _count_unique_matches() checks both mappings with respective matchers
- _record_matches() now takes only matched_kw100 (context keywords never tracked)
- cleanup_orphaned_rooms() rebuilds both mappings

TEIL 2 — room-map.json (data, not in git):
- Removed 39 space-variant dual keywords (e.g. 'presence engine' removed,
  'presence-engine' kept). No longer needed since match_keyword_exact
  is hyphen-insensitive.
- Backup: .bak-pre-curation-20260805

Tests: 35/35 passed (pytest -k booster)
2026-08-05 05:43:14 +02:00

74 lines
2.7 KiB
Python

"""FAISS + Booster Smoke-Test: kombinierte Similarity + Keyword-Diskriminierung."""
import sys
sys.path.insert(0, "plugin")
from archivar.room_map import RoomMap
from archivar.classifier import OllamaEmbeddingClient
from archivar.room_index import RoomIndexManager
from archivar.booster import KeywordBooster
def main() -> int:
room_map = RoomMap.load()
emb = OllamaEmbeddingClient()
idx = RoomIndexManager(room_map, emb)
if not idx.load():
print("FEHLER: Index nicht geladen")
return 1
booster = KeywordBooster(room_map)
tests = [
("Der Docker-Container startet nicht nach docker compose up", "BAT-Team"),
("Die install.sh muss alle Secrets generieren", "Rocketchat-Plugin"),
("Das Subnetz braucht eine Dokumentation", "LAN-Dokumentation"),
("IMAP-IDLE funktioniert nicht mit der Proton Bridge", "Protonbridge-Plugin"),
("Der Archivar routet falsch bei BUTTON_CLICK", "Rocketchat-Plugin"),
("pg_dump scheitert an Version-Mismatch v15 vs v16", "BAT-Team"),
("Proxmox Server hat hohe IO-Wait Zeiten", "LAN-Dokumentation"),
("Himalaya CLI kann keine Emails via SMTP senden", "Protonbridge-Plugin"),
]
print(f"FAISS+Booster Smoke-Test: {idx.size} Raeume, Version {idx._version}")
print(f"Booster: {len(booster._kw100_to_rooms)} kw100 + {len(booster._kwctx_to_rooms)} kwctx Keywords, +0.10/unique")
print()
ok = 0
for text, expected in tests:
# FAISS-Suche
faiss_hits = idx.search_text(text, k=3, min_score=0.3)
if not faiss_hits:
print(f"❌ NO FAISS HIT | {text[:60]}")
continue
# Booster anwenden (IMMER, wie im neuen router.py)
boosted = booster.boost(text, faiss_hits)
top_id, top_score = boosted[0]
top_room = room_map.get_room_by_id(top_id)
top_name = top_room.name if top_room else "?"
# Vergleich: FAISS-only vs FAISS+Booster
faiss_top_id, faiss_top_score = faiss_hits[0]
faiss_top_room = room_map.get_room_by_id(faiss_top_id)
faiss_top_name = faiss_top_room.name if faiss_top_room else "?"
match = "✅" if expected in top_name else "❌"
changed = "🔄" if faiss_top_name != top_name else " "
others = ", ".join(
f"{room_map.get_room_by_id(r).name}({s:.2f})"
for r, s in boosted[1:]
)
print(f"{match} {changed} {top_score:.3f} → {top_name:25s} | {text[:55]}")
if match == "✅":
ok += 1
else:
print(f" FAISS-only: {faiss_top_name}({faiss_top_score:.3f}), others: {others}")
print(f"\n{ok}/{len(tests)} korrekt (mit Booster)")
return 0 if ok >= 6 else 1
if __name__ == "__main__":
raise SystemExit(main())