feat: V8.3.3 — Routing-Telemetrie (Konfidenz-Logging) + Echte Integration-Tests
FEATURE 1: Routing-Telemetrie (Konfidenz-Logging) - Neue Datei: archivar/routing_telemetry.py — RoutingTelemetry Klasse - Feature-Flag: ARCHIVAR_ROUTING_TELEMETRY env var (Default true) - Pro Routing-Entscheidung: stage, score, decision, target, origin, duration_ms - Format: [TELEMETRY] stage=keyword_100 score=1.00 decision=route ... - NIEMALS Nachrichteninhalte im Log (Datenschutz) - Telemetrie-Punkte in router.py an allen 5 Stufen: keyword_100, context_keyword, faiss, llm, default - Flush in adapter.py nach classify_and_route() FEATURE 2: Echte Integration-Tests - Neue Datei: archivar/tests/test_v8_3_3.py (18 Tests) - Echte RoutingDecision-Objekte statt Dict-Simulationen - 7 Integration-Test-Klassen: 1. 100%-Keyword im falschen Raum → route 2. 100%-Keyword im richtigen Raum → stay (self-match) 3. Kontext-Keyword → butler 4. FAISS hohe Ähnlichkeit → route 5. FAISS mittlere Ähnlichkeit → butler 6. LLM → STAY 7. LLM → ROUTE - Telemetrie-Tests: Logging, Datenschutz, Feature-Flag - Erweiterte conftest.py: multi_room_map, Mock-LLM Fixtures Verifikation: 527 passed, 1 pre-existing fail, 2 skipped (FAISS)
This commit is contained in:
@@ -32,6 +32,7 @@ from .room_index import RoomIndexManager
|
||||
from .booster import KeywordBooster
|
||||
from .archivar_state import ArchivarState
|
||||
from .routing_counter import routing_counter
|
||||
from .routing_telemetry import routing_telemetry
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -563,6 +564,7 @@ class BidirectionalRouter:
|
||||
)
|
||||
|
||||
# ── Schritt 3: Keyword-Match (aus RoomMap) ──────────────────
|
||||
routing_telemetry.start_timer()
|
||||
matched_room = self._room_map.find_room_by_keywords(text, origin_room_id=origin_room_id)
|
||||
if matched_room is not None:
|
||||
# Self-Match-Schutz: Wenn Keyword-Match den Ursprungsraum
|
||||
@@ -607,6 +609,11 @@ class BidirectionalRouter:
|
||||
text[:80], matched_room.name,
|
||||
)
|
||||
routing_counter.increment('keyword_100_auto_route')
|
||||
routing_telemetry.record(
|
||||
stage='keyword_100', score=1.0, decision='route',
|
||||
target=matched_room.room_id, origin=origin_room_id,
|
||||
duration_ms=routing_telemetry.elapsed_ms(),
|
||||
)
|
||||
logger.info("ROUTING DECISION: reason=keyword_100_auto_route, origin_room=%s, target_room=%s, stay=False, butler_mode=False", origin_room_id, matched_room.room_id)
|
||||
return RoutingDecision(
|
||||
category="work_order",
|
||||
@@ -626,6 +633,11 @@ class BidirectionalRouter:
|
||||
text[:80], matched_room.name,
|
||||
)
|
||||
routing_counter.increment('keyword_context_butler')
|
||||
routing_telemetry.record(
|
||||
stage='context_keyword', score=0.95, decision='butler',
|
||||
target=matched_room.room_id, origin=origin_room_id,
|
||||
duration_ms=routing_telemetry.elapsed_ms(),
|
||||
)
|
||||
logger.info("ROUTING DECISION: reason=keyword_context_butler, origin_room=%s, target_room=%s, stay=False, butler_mode=True", origin_room_id, matched_room.room_id)
|
||||
return RoutingDecision(
|
||||
category="work_order",
|
||||
@@ -644,6 +656,7 @@ class BidirectionalRouter:
|
||||
# Phase-1 routet direkt bei hohem FAISS-Score — kein LLM-Aufruf.
|
||||
# Übersprungen wenn _room_index oder _booster None sind.
|
||||
if self._room_index is not None and self._room_index.is_built:
|
||||
routing_telemetry.start_timer()
|
||||
faiss_hits = self._room_index.search_text(
|
||||
text, k=FAISS_TOP_K, min_score=FAISS_MIN_SCORE
|
||||
)
|
||||
@@ -703,6 +716,11 @@ class BidirectionalRouter:
|
||||
booster_applied,
|
||||
)
|
||||
routing_counter.increment('faiss_auto_route')
|
||||
routing_telemetry.record(
|
||||
stage='faiss', score=top_score, decision='route',
|
||||
target=top_room_id, origin=origin_room_id,
|
||||
duration_ms=routing_telemetry.elapsed_ms(),
|
||||
)
|
||||
logger.info("ROUTING DECISION: reason=faiss_auto_route, origin_room=%s, target_room=%s, stay=False, butler_mode=False", origin_room_id, top_room_id)
|
||||
|
||||
return RoutingDecision(
|
||||
@@ -729,6 +747,11 @@ class BidirectionalRouter:
|
||||
FAISS_AUTO_ROUTE,
|
||||
)
|
||||
routing_counter.increment('faiss_butler')
|
||||
routing_telemetry.record(
|
||||
stage='faiss', score=top_score, decision='butler',
|
||||
target=top_room_id, origin=origin_room_id,
|
||||
duration_ms=routing_telemetry.elapsed_ms(),
|
||||
)
|
||||
logger.info("ROUTING DECISION: reason=faiss_butler, origin_room=%s, target_room=%s, stay=False, butler_mode=True", origin_room_id, top_room_id)
|
||||
|
||||
# ── Schritt 4: Embedding-Vorfilter (binär) ────────────────────
|
||||
@@ -832,6 +855,7 @@ class BidirectionalRouter:
|
||||
# ── Schritt 5: LLM-Raum-Router (zentraler Prompt) ────────────
|
||||
# LLM_ROOM_PROMPT erhält Nachricht + Raumliste mit Keywords,
|
||||
# liefert STAY oder room_id direkt (keine Kategorien, kein Name-Matching)
|
||||
routing_telemetry.start_timer()
|
||||
llm_room, llm_stay, llm_failed = await self._llm_room_lookup(text, origin_room_id)
|
||||
|
||||
# ── Schritt 6: ORIGIN-FIRST GUARD (v6) ──────────────────────
|
||||
@@ -844,6 +868,11 @@ class BidirectionalRouter:
|
||||
text,
|
||||
)
|
||||
routing_counter.increment('llm_stay')
|
||||
routing_telemetry.record(
|
||||
stage='llm', score=0.0, decision='stay',
|
||||
target='', origin=origin_room_id,
|
||||
duration_ms=routing_telemetry.elapsed_ms(),
|
||||
)
|
||||
logger.info("ROUTING DECISION: reason=llm_stay, origin_room=%s, target_room=, stay=True, butler_mode=False", origin_room_id)
|
||||
return RoutingDecision(
|
||||
category="direct_question",
|
||||
@@ -859,6 +888,11 @@ class BidirectionalRouter:
|
||||
"LLM-Raum-Router: STAY für '%.80s...' → stay_in_room", text[:80]
|
||||
)
|
||||
routing_counter.increment('llm_stay')
|
||||
routing_telemetry.record(
|
||||
stage='llm', score=0.0, decision='stay',
|
||||
target='', origin=origin_room_id,
|
||||
duration_ms=routing_telemetry.elapsed_ms(),
|
||||
)
|
||||
logger.info("ROUTING DECISION: reason=llm_stay, origin_room=%s, target_room=, stay=True, butler_mode=False", origin_room_id)
|
||||
return RoutingDecision(
|
||||
category="direct_question",
|
||||
@@ -927,6 +961,11 @@ class BidirectionalRouter:
|
||||
text[:80], llm_room.name, llm_room.room_id[:8],
|
||||
)
|
||||
routing_counter.increment('llm_route')
|
||||
routing_telemetry.record(
|
||||
stage='llm', score=0.90, decision='butler',
|
||||
target=llm_room.room_id, origin=origin_room_id,
|
||||
duration_ms=routing_telemetry.elapsed_ms(),
|
||||
)
|
||||
logger.info("ROUTING DECISION: reason=llm_route, origin_room=%s, target_room=%s, stay=False, butler_mode=True", origin_room_id, llm_room.room_id)
|
||||
|
||||
return RoutingDecision(
|
||||
@@ -945,6 +984,11 @@ class BidirectionalRouter:
|
||||
"route(): Unerwarteter Fehler für '%.80s...' — Fallback auf Catch-All: %s",
|
||||
text, e, exc_info=True,
|
||||
)
|
||||
routing_telemetry.record(
|
||||
stage='default', score=0.0, decision='stay',
|
||||
target='', origin=origin_room_id,
|
||||
duration_ms=0.0,
|
||||
)
|
||||
catch_all = self._room_map.catch_all_room
|
||||
return RoutingDecision(
|
||||
category="direct_question",
|
||||
|
||||
Reference in New Issue
Block a user