diff --git a/scripts/rebuild_index.py b/scripts/rebuild_index.py new file mode 100644 index 0000000..918830c --- /dev/null +++ b/scripts/rebuild_index.py @@ -0,0 +1,28 @@ +"""Rebuild Archivar v5 FAISS index from current room-map.json.""" +import sys + +sys.path.insert(0, "plugin") + +from archivar.room_map import RoomMap +from archivar.classifier import OllamaEmbeddingClient +from archivar.room_index import RoomIndexManager + + +def main() -> int: + room_map = RoomMap.load() + print( + f"RoomMap geladen: {len(room_map.rooms)} rooms, Version {room_map.version}" + ) + + emb = OllamaEmbeddingClient() + idx = RoomIndexManager(room_map, emb) + idx.build_index() + print(f"Index gebaut: {idx.size} rooms, Version {idx._version}") + + idx.save() + print(f"Gespeichert: {idx.index_path} + {idx.meta_path}") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/scripts/smoke_test_booster.py b/scripts/smoke_test_booster.py new file mode 100644 index 0000000..b551897 --- /dev/null +++ b/scripts/smoke_test_booster.py @@ -0,0 +1,73 @@ +"""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()) diff --git a/scripts/smoke_test_faiss.py b/scripts/smoke_test_faiss.py new file mode 100644 index 0000000..82b7ad2 --- /dev/null +++ b/scripts/smoke_test_faiss.py @@ -0,0 +1,57 @@ +"""FAISS Smoke-Test: granulare Similarity mit 200-Wort-Beschreibungen.""" +import sys +sys.path.insert(0, "plugin") + +from archivar.room_map import RoomMap +from archivar.classifier import OllamaEmbeddingClient +from archivar.room_index import RoomIndexManager + + +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 + + 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 Smoke-Test: {idx.size} RΓ€ume, Version {idx._version}") + print() + + ok = 0 + for text, expected in tests: + hits = idx.search_text(text, k=3, min_score=0.3) + if hits: + top_id, top_score = hits[0] + top_room = room_map.get_room_by_id(top_id) + top_name = top_room.name if top_room else "?" + match = "βœ…" if expected in top_name else "❌" + others = ", ".join( + f"{room_map.get_room_by_id(r).name}({s:.2f})" + for r, s in hits[1:] + ) + print(f"{match} {top_score:.3f} β†’ {top_name:25s} | {text[:60]}") + if match == "βœ…": + ok += 1 + else: + print(f" expected: {expected}, others: {others}") + else: + print(f"❌ NO HIT (score < 0.3) | {text[:60]}") + + print(f"\n{ok}/{len(tests)} korrekt") + return 0 if ok >= len(tests) * 0.75 else 1 + + +if __name__ == "__main__": + raise SystemExit(main())