neuer semantik retriever im Chat

This commit is contained in:
Lars committed 2025-12-18 12:40:34 +01:00
1 parent 43f695de54
commit 7f7d8c87db
3 files changed
+49 -13

No files matched your search

+10 -7
View File
@@ -1,10 +1,9 @@
"""
FILE: app/models/dto.py
DESCRIPTION: Pydantic-Modelle (DTOs) für Request/Response Bodies. Definiert das API-Schema.
VERSION: 0.6.2
VERSION: 2.6.0 (WP-22 Semantic Graph Routing & Lifecycle)
STATUS: Active
DEPENDENCIES: pydantic, typing, uuid
LAST_ANALYSIS: 2025-12-15
"""
from __future__ import annotations
@@ -12,7 +11,7 @@ from pydantic import BaseModel, Field
from typing import List, Literal, Optional, Dict, Any
import uuid
EdgeKind = Literal["references", "references_at", "backlink", "next", "prev", "belongs_to", "depends_on", "related_to", "similar_to"]
EdgeKind = Literal["references", "references_at", "backlink", "next", "prev", "belongs_to", "depends_on", "related_to", "similar_to", "caused_by", "derived_from", "based_on", "solves", "blocks", "uses", "guides"]
# --- Basis-DTOs ---
@@ -56,6 +55,11 @@ class QueryRequest(BaseModel):
filters: Optional[Dict] = None
ret: Dict = {"with_paths": True, "with_notes": True, "with_chunks": True}
explain: bool = False
# WP-22: Semantic Graph Routing
# Erlaubt dem Router, Kantengewichte dynamisch zu überschreiben.
# Format: {"caused_by": 3.0, "related_to": 0.5}
boost_edges: Optional[Dict[str, float]] = None
class FeedbackRequest(BaseModel):
@@ -97,7 +101,8 @@ class ScoreBreakdown(BaseModel):
class Reason(BaseModel):
"""Ein semantischer Grund für das Ranking."""
kind: Literal["semantic", "edge", "type", "centrality"]
# WP-22: 'lifecycle' hinzugefügt für Status-Begründungen (Draft vs Stable)
kind: Literal["semantic", "edge", "type", "centrality", "lifecycle"]
message: str
score_impact: Optional[float] = None
details: Optional[Dict[str, Any]] = None
@@ -151,6 +156,4 @@ class ChatResponse(BaseModel):
sources: List[QueryHit] = Field(..., description="Die für die Antwort genutzten Quellen")
latency_ms: int
intent: Optional[str] = Field("FACT", description="WP-06: Erkannter Intent (FACT/DECISION)")
intent_source: Optional[str] = Field("Unknown", description="WP-06: Quelle der Intent-Erkennung (Keyword vs. LLM)")
intent_source: Optional[str] = Field("Unknown", description="WP-06: Quelle der Intent-Erkennung (Keyword vs. LLM)")
+13 -4
View File
@@ -1,11 +1,10 @@
"""
FILE: app/routers/chat.py
DESCRIPTION: Haupt-Chat-Interface (RAG & Interview). Enthält Intent-Router (Keywords/LLM) und Prompt-Construction.
VERSION: 2.5.0
VERSION: 2.6.0 (WP-22 Semantic Graph Routing)
STATUS: Active
DEPENDENCIES: app.config, app.models.dto, app.services.llm_service, app.core.retriever, app.services.feedback_service
EXTERNAL_CONFIG: config/decision_engine.yaml, config/types.yaml
LAST_ANALYSIS: 2025-12-15
"""
from fastapi import APIRouter, HTTPException, Depends
@@ -281,12 +280,20 @@ async def chat_endpoint(
# --- RAG MODE ---
inject_types = strategy.get("inject_types", [])
prepend_instr = strategy.get("prepend_instruction", "")
# --- WP-22: Semantic Graph Routing ---
# Wir laden die konfigurierten Edge-Boosts für diesen Intent
edge_boosts = strategy.get("edge_boosts", {})
if edge_boosts:
logger.info(f"[{query_id}] Applying Edge Boosts: {edge_boosts}")
query_req = QueryRequest(
query=request.message,
mode="hybrid",
top_k=request.top_k,
explain=request.explain
explain=request.explain,
# WP-22: Boosts weitergeben
boost_edges=edge_boosts
)
retrieve_result = await retriever.search(query_req)
hits = retrieve_result.results
@@ -297,7 +304,9 @@ async def chat_endpoint(
mode="hybrid",
top_k=3,
filters={"type": inject_types},
explain=False
explain=False,
# WP-22: Boosts auch hier anwenden (Konsistenz)
boost_edges=edge_boosts
)
strategy_result = await retriever.search(strategy_req)
existing_ids = {h.node_id for h in hits}