"""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._keyword_to_rooms)} Keywords, immer aktiv, +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())