# Architekturskizze: Zweistufiges Keyword-Evidenz-System ## Überblick Das zweistufige Keyword-Evidenz-System trennt eindeutige Keywords (100% Evidenz) von mehrdeutigen Keywords (<100% Evidenz), um die Routing-Genauigkeit zu verbessern und manuelle Pflege zu reduzieren. ## 1. Neue room-map.json-Struktur Die bestehende flache `keywords`-Liste wird in zwei separate Listen aufgeteilt: ```json { "version": 2, "rooms": { "6a19b0ff02aeecd36b1aa16c": { "name": "#Rocketchat-Plugin", "theme": "Hermes Plugin Rocketchat, RC, rocket.chat, Austausch und Status zum Projekt Rocketchat", "keywords_100": ["rocketchat", "rc", "ddp", "websocket", "adapter", "install.sh", "hermes"], "keywords_context": ["plugin", "gateway", "deployment", "button", "sync"], "catch_all": false }, "69f8beaef06dba03be82f9fc": { "name": "#Protonbridge-Plugin", "theme": "Hermes Plugin Protonbridge, Proton Mail Bridge, Austausch und Status zum Projekt Protonbridge", "keywords_100": ["protonbridge", "proton", "mail", "bridge", "email", "smtp", "imap"], "keywords_context": ["plugin", "deployment"], "catch_all": false }, "6a049d493a62ef8f1ead2320": { "name": "#BAT-Team", "theme": "Trading-Plattform, Multi-Agent-System, Bot-Agenten-Team, Krypto-Analysen, Wyckoff-Methodik, Boot-Window, Entwicklung und Betrieb der BAT-Trading-Plattform", "keywords_100": ["bat", "bat-team", "trading", "krypto", "wyckoff", "boot-window", "börse", "exchange", "analyst", "control-tower"], "keywords_context": ["gateway"], "catch_all": false }, "6a1c56d4b73efec2bebec2db": { "name": "#LAN-Dokumentation", "theme": "HomeLab, home lab, Dokumentation des LAN, Austausch und Status zum Projekt LAN-Dokumentation", "keywords_100": ["lan", "dokumentation", "homelab", "netzwerk", "router", "switch", "subnetz", "proxmox", "heimnetz", "ip-adresse"], "keywords_context": [], "catch_all": false }, "69f4e777f06dba03be82dce7": { "name": "DM mit Andreas", "theme": "Direktnachrichten — Catch-All für alle Themen ohne eigenen Raum", "keywords_100": [], "keywords_context": [], "catch_all": true } }, "excluded_rooms": [ "6a049d493a62ef8f1ead2320", "6a1c56d4b73efec2bebec2db", "69f8beaef06dba03be82f9fc", "6a19b0ff02aeecd36b1aa16c", "6a0f4b2991db1dbf570a5442", "6a21495ede3de7118e84d82e" ], "fact_store_path": "/data/Wissensdatenbank/0100 Inbox" } ``` ## 2. Keyword-Matcher Algorithmus Der neue Matcher verarbeitet Keywords in zwei Stufen: ### Stufe 1: 100% Evidenz Keywords ```python def find_room_by_keywords(self, text: str, min_score: int = 2, origin_room_id: Optional[str] = None) -> Optional[RoomEntry]: """Find the room with the most keyword matches for *text*.""" # Stufe 1: Prüfe 100% Evidenz Keywords zuerst text_lower = text.lower() for room in self._rooms.values(): if room.catch_all: continue # Prüfe ob 100% Keywords matchen if any(kw in text_lower for kw in room.keywords_100): return room # Stufe 2: Origin-Priorität mit kontextabhängigen Keywords 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 in text_lower) if context_score >= min_score: return origin_room # Stufe 3: Globaler Scan mit kontextabhängigen Keywords best_room: Optional[RoomEntry] = None best_score: int = 0 for room in self._rooms.values(): if room.catch_all: continue # Prüfe kontextabhängige Keywords context_score = sum(1 for kw in room.keywords_context if kw in text_lower) if context_score > best_score: best_score = context_score best_room = room if best_room is not None and best_score >= min_score: return best_room return None ``` ## 3. Selbstlernendes System (Optional) ### Datenstruktur In `archivar_state.json` wird eine neue Sektion für Keyword-Gewichte hinzugefügt: ```json { "rooms": { "6a19b0ff02aeecd36b1aa16c": { "stay_decision": "ask", "decided_at": "2026-06-12T10:30:00", "decided_by": "Andreas" } }, "keyword_weights": { "plugin": { "6a19b0ff02aeecd36b1aa16c": 0.7, # #Rocketchat-Plugin "69f8beaef06dba03be82f9fc": 0.3 # #Protonbridge-Plugin }, "gateway": { "6a19b0ff02aeecd36b1aa16c": 0.6, # #Rocketchat-Plugin "6a049d493a62ef8f1ead2320": 0.4 # #BAT-Team } } } ``` ### Lernalgorithmus 1. **Ereignis**: Andreas klickt "✅Ja" (rüberkopieren) im Kontext eines Keywords 2. **Gewichtsanpassung**: - Erhöhe Gewicht für das aktuelle Zimmer um 0.1 - Dämpfung: Maximalgewicht 0.9, Mindestgewicht 0.1 - Verteile das reduzierte Gewicht gleichmäßig auf andere Zimmer 3. **Schwellwert**: Nach 3 Bestätigungen wird das Keyword in `keywords_100` verschoben ### Persistenz ```python @dataclass class KeywordWeights: """Gewichte für kontextabhängige Keywords.""" weights: Dict[str, Dict[str, float]] = field(default_factory=dict) # keyword → {room_id → weight} class ArchivarState: # ... bestehende Methoden ... def get_keyword_weight(self, keyword: str, room_id: str) -> float: """Hole das Gewicht für ein Keyword in einem Raum.""" return self._keyword_weights.get(keyword, {}).get(room_id, 0.0) def update_keyword_weight(self, keyword: str, room_id: str, positive: bool) -> bool: """Aktualisiere das Gewicht basierend auf Benutzerfeedback.""" # Implementierung des Lernalgorithmus pass ``` ## 4. Migrationspfad ### Phase 1: Abwärtskompatibel - Bestehende `keywords`-Liste wird als `keywords_context` interpretiert - Neue `keywords_100` bleibt leer - Version bleibt auf 1, neue Felder werden ignoriert ### Phase 2: Upgrade - Automatische Migration bei Erkennung von Version 1 - Manuelles Review zur Klassifizierung von Keywords - Version auf 2 erhöhen ## 5. Betroffene Dateien ### Geänderte Dateien: - `room_map.py` - Keyword-Matcher Logik - `archivar_state.py` - Keyword-Gewichte Persistenz - `room-map.json` - Neue Struktur (abwärtskompatibel) ### Neue Dateien: - `keyword_weights.json` (optional) - Separate Datei für Keyword-Gewichte ## 6. Pitfalls und Lösungen ### Abwärtskompatibilität - **Problem**: Bestehende Installationen brechen - **Lösung**: Versionierung und automatische Migration ### Lernrate - **Problem**: Zu schnelles oder zu langsames Lernen - **Lösung**: Gedämpfte Lernrate mit Min/Max-Begrenzungen ### Manuelle Overrides - **Problem**: Gelernte Gewichte überschreiben manuelle Entscheidungen - **Lösung**: Manuelle Entscheidungen haben immer Vorrang ### Performance - **Problem**: Komplexere Matching-Logik verlangsamt den Matcher - **Lösung**: Caching und optimierte Datenstrukturen