feat(archivar): Booster-Gewichtung verstärkt — FAISS + Keywords

Booster-Strategie: IMMER aktiv (nicht nur bei Konflikten)
- router.py: Konfliktbedingung entfernt, Booster auf alle FAISS-Treffer
- booster.py: Boost +0.05→+0.10, zusätzlich +0.05 pro weiterem unique Keyword
- config.py: FAISS_AUTO_ROUTE 0.85→0.70

Kombiniert semantische Breite (FAISS) mit präziser Keyword-Diskriminierung.
Ziel: granulare Raum-Entscheidungen bei überlappenden Themen.
This commit is contained in:
Bernd (Hermes)
2026-06-18 07:55:14 +02:00
parent 97d59f5272
commit d005eb769d
3 changed files with 42 additions and 25 deletions
+34 -11
View File
@@ -2,9 +2,10 @@
Keyword-Booster für Archivar v5.
Verfeinert FAISS-Suchergebnisse durch Keyword-Analyse:
- Eindeutige Keywords (nur in einem Raum) geben +0.05 Boost
- Eindeutige Keywords (nur in einem Raum) geben +0.10 Boost
- Mehrere eindeutige Keywords geben zusätzlichen Boost (+0.05 pro weiterem Keyword)
- Mehrdeutige Keywords sind neutral
- Bei knappen Top-2 entscheidet die Anzahl eindeutiger Keywords
- Bei knappen Top-2 entscheidet die Anzahl eindeutiger Keywords (+0.05 Boost)
Usage::
@@ -17,7 +18,7 @@ Usage::
scores = [("room_a", 0.87), ("room_b", 0.85), ("room_c", 0.62)]
text = "Das Plugin hat einen Bug im Router"
boosted = booster.boost(text, scores)
# → [("room_a", 0.92), ("room_b", 0.85), ("room_c", 0.62)]
# → [("room_a", 0.97), ("room_b", 0.85), ("room_c", 0.62)]
"""
from __future__ import annotations
@@ -107,19 +108,41 @@ class KeywordBooster:
# Keine Keywords → Scores unverändert zurück
return sorted(scores, key=lambda x: x[1], reverse=True)
# ── Boost-Phase: +0.05 für eindeutige Keywords ────────────
# ── Boost-Phase: +0.10 für eindeutige Keywords ────────────
for kw in matched_keywords:
rooms = self._keyword_to_rooms[kw]
if len(rooms) == 1:
unique_room = next(iter(rooms))
if unique_room in score_dict:
score_dict[unique_room] += 0.05
score_dict[unique_room] += 0.10
logger.debug(
"Boost +0.05: keyword='%s' → room='%s' (unique)",
"Boost +0.10: keyword='%s' → room='%s' (unique)",
kw,
unique_room[:8],
)
# ── Zusätzlicher Boost für mehrere eindeutige Keywords ────
# Zähle eindeutige Keywords pro Raum und gib Bonus für hohe Anzahl
unique_counts_per_room: Dict[str, int] = {}
for kw in matched_keywords:
rooms = self._keyword_to_rooms[kw]
if len(rooms) == 1:
unique_room = next(iter(rooms))
if unique_room in score_dict:
unique_counts_per_room[unique_room] = unique_counts_per_room.get(unique_room, 0) + 1
# Bonus: +0.05 für jeden weiteren unique Match über dem ersten
for room_id, count in unique_counts_per_room.items():
if count > 1:
additional_boost = (count - 1) * 0.05
score_dict[room_id] += additional_boost
logger.debug(
"Additional boost +%s: room='%s' has %d unique keywords",
additional_boost,
room_id[:8],
count,
)
# ── Nach Boost sortieren ──────────────────────────────────
boosted = sorted(score_dict.items(), key=lambda x: x[1], reverse=True)
@@ -129,23 +152,23 @@ class KeywordBooster:
top2_room, top2_score = boosted[1]
diff = top1_score - top2_score
if diff < 0.03:
if diff < 0.05:
# Zähle eindeutige Keyword-Treffer für beide Räume
unique_count_1 = self._count_unique_matches(text_lower, top1_room)
unique_count_2 = self._count_unique_matches(text_lower, top2_room)
if unique_count_1 > unique_count_2:
score_dict[top1_room] += 0.02
score_dict[top1_room] += 0.05
logger.debug(
"Conflict resolution: +0.02 for '%s' (%d unique vs %d)",
"Conflict resolution: +0.05 for '%s' (%d unique vs %d)",
top1_room[:8],
unique_count_1,
unique_count_2,
)
elif unique_count_2 > unique_count_1:
score_dict[top2_room] += 0.02
score_dict[top2_room] += 0.05
logger.debug(
"Conflict resolution: +0.02 for '%s' (%d unique vs %d)",
"Conflict resolution: +0.05 for '%s' (%d unique vs %d)",
top2_room[:8],
unique_count_2,
unique_count_1,
+2 -2
View File
@@ -228,9 +228,9 @@ Enthält Entscheidungen wie "immer im Raum bleiben" oder "nie routen".
# Bei mittlerem Score greift der Keyword-Booster zur Konfliktlösung.
# Bei niedrigem Score fällt der Flow an den Embedding-Vorfilter + LLM durch.
FAISS_AUTO_ROUTE: float = 0.85
FAISS_AUTO_ROUTE: float = 0.70
"""FAISS-Score-Schwelle für automatisches Routing ohne LLM.
Nachrichten mit FAISS-Score >= 0.85 (nach Keyword-Boost) werden direkt
Nachrichten mit FAISS-Score >= 0.70 (nach Keyword-Boost) werden direkt
geroutet — kein LLM-Aufruf nötig. Spart ~2.4s Latenz pro Nachricht."""
FAISS_MIN_SCORE: float = 0.50
+6 -12
View File
@@ -343,18 +343,12 @@ class BidirectionalRouter:
boosted = faiss_hits
booster_applied = False
if self._booster is not None:
# Nur boosten wenn Top-2 knapp beieinander liegen
if (
len(faiss_hits) >= 2
and (faiss_hits[0][1] - faiss_hits[1][1]) < FAISS_CONFLICT_DIFF
):
boosted = self._booster.boost(text, faiss_hits)
booster_applied = True
logger.debug(
"FAISS Booster applied: diff=%.3f < %.3f",
faiss_hits[0][1] - faiss_hits[1][1],
FAISS_CONFLICT_DIFF,
)
# Boosten immer anwenden, nicht nur bei Konflikten
boosted = self._booster.boost(text, faiss_hits)
booster_applied = True
logger.debug(
"FAISS Booster applied: always active",
)
top_room_id, top_score = boosted[0]