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,