neu version
This commit is contained in:
1 parent
48729e6f5d
commit
2c3ee8efd6
6 files changed
+133
-130
No files matched your search
@@ -4,7 +4,7 @@ DESCRIPTION: Haupt-Ingestion-Logik.
|
||||
FIX: Korrekte Priorisierung von Frontmatter für chunk_profile und retriever_weight.
|
||||
Lade Chunk-Config basierend auf dem effektiven Profil, nicht nur dem Notiz-Typ.
|
||||
WP-22: Integration von Content Lifecycle (Status) und Edge Registry.
|
||||
VERSION: 2.8.0 (WP-22 Lifecycle & Registry)
|
||||
VERSION: 2.8.1 (WP-22 Lifecycle & Registry)
|
||||
STATUS: Active
|
||||
DEPENDENCIES: app.core.parser, app.core.note_payload, app.core.chunker, app.core.derive_edges, app.core.qdrant*, app.services.embeddings_client, app.services.edge_registry
|
||||
EXTERNAL_CONFIG: config/types.yaml
|
||||
@@ -159,7 +159,7 @@ class IngestionService:
|
||||
logger.error(f"Validation failed for {file_path}: {e}")
|
||||
return {**result, "error": f"Validation failed: {str(e)}"}
|
||||
|
||||
# --- WP-22: Content Lifecycle Gate ---
|
||||
# --- WP-22: Content Lifecycle Gate (Teil A) ---
|
||||
status = fm.get("status", "draft").lower().strip()
|
||||
|
||||
# Hard Skip für System-Dateien
|
||||
@@ -265,7 +265,7 @@ class IngestionService:
|
||||
except TypeError:
|
||||
raw_edges = build_edges_for_note(note_id, chunk_pls)
|
||||
|
||||
# --- WP-22: Edge Registry Validation ---
|
||||
# --- WP-22: Edge Registry Validation (Teil B) ---
|
||||
edges = []
|
||||
if raw_edges:
|
||||
for edge in raw_edges:
|
||||
|
||||
+26
-26
@@ -2,7 +2,7 @@
|
||||
FILE: app/core/retriever.py
|
||||
DESCRIPTION: Implementiert die Hybrid-Suche (Vektor + Graph-Expansion) und das Scoring-Modell (Explainability).
|
||||
WP-22 Update: Dynamic Edge Boosting & Lifecycle Scoring.
|
||||
VERSION: 0.6.0 (WP-22 Dynamic Scoring)
|
||||
VERSION: 0.6.1 (WP-22 Dynamic Scoring)
|
||||
STATUS: Active
|
||||
DEPENDENCIES: app.config, app.models.dto, app.core.qdrant*, app.services.embeddings_client, app.core.graph_adapter
|
||||
LAST_ANALYSIS: 2025-12-18
|
||||
@@ -98,16 +98,15 @@ def _semantic_hits(
|
||||
results.append((str(pid), float(score), dict(payload or {})))
|
||||
return results
|
||||
|
||||
# --- WP-22 Helper: Lifecycle Multipliers ---
|
||||
# --- WP-22 Helper: Lifecycle Multipliers (Teil A) ---
|
||||
def _get_status_multiplier(payload: Dict[str, Any]) -> float:
|
||||
"""
|
||||
WP-22: Drafts werden bestraft, Stable Notes belohnt.
|
||||
WP-22: stable (1.2), active (1.0), draft (0.5).
|
||||
"""
|
||||
status = str(payload.get("status", "draft")).lower()
|
||||
status = str(payload.get("status", "active")).lower()
|
||||
if status == "stable": return 1.2
|
||||
if status == "active": return 1.0
|
||||
if status == "draft": return 0.8 # Malus für Entwürfe
|
||||
# Fallback für andere oder leere Status
|
||||
if status == "draft": return 0.5
|
||||
return 1.0
|
||||
|
||||
def _compute_total_score(
|
||||
@@ -118,8 +117,7 @@ def _compute_total_score(
|
||||
dynamic_edge_boosts: Dict[str, float] = None
|
||||
) -> Tuple[float, float, float]:
|
||||
"""
|
||||
Berechnet total_score.
|
||||
WP-22 Update: Integration von Status-Bonus und Dynamic Edge Boosts.
|
||||
Berechnet total_score nach WP-22 Scoring Formel.
|
||||
"""
|
||||
raw_weight = payload.get("retriever_weight", 1.0)
|
||||
try:
|
||||
@@ -132,13 +130,13 @@ def _compute_total_score(
|
||||
sem_w, edge_w, cent_w = _get_scoring_weights()
|
||||
status_mult = _get_status_multiplier(payload)
|
||||
|
||||
# Dynamic Edge Boosting
|
||||
# Wenn dynamische Boosts aktiv sind, erhöhen wir den Einfluss des Graphen
|
||||
# Dies ist eine Vereinfachung, da der echte Boost im Subgraph passiert sein sollte.
|
||||
# Dynamic Edge Boosting (Teil C)
|
||||
# Globaler Bonus falls Kanten-spezifische Boosts aktiv sind (z.B. WHY Frage)
|
||||
# Die kanten-spezifische Gewichtung passiert bereits im Subgraph in hybrid_retrieve.
|
||||
final_edge_score = edge_w * edge_bonus
|
||||
if dynamic_edge_boosts and edge_bonus > 0:
|
||||
# Globaler Boost für Graph-Signale bei spezifischen Intents
|
||||
final_edge_score *= 1.2
|
||||
# Globaler Verstärker für Graph-Signale bei spezifischen Intents
|
||||
final_edge_score *= 1.5
|
||||
|
||||
total = (sem_w * float(semantic_score) * weight * status_mult) + final_edge_score + (cent_w * cent_bonus)
|
||||
return float(total), float(edge_bonus), float(cent_bonus)
|
||||
@@ -154,7 +152,7 @@ def _build_explanation(
|
||||
subgraph: Optional[ga.Subgraph],
|
||||
node_key: Optional[str]
|
||||
) -> Explanation:
|
||||
"""Erstellt ein Explanation-Objekt."""
|
||||
"""Erstellt ein Explanation-Objekt (WP-04b)."""
|
||||
sem_w, _edge_w, _cent_w = _get_scoring_weights()
|
||||
# Scoring weights erneut laden für Reason-Details
|
||||
_, edge_w_cfg, cent_w_cfg = _get_scoring_weights()
|
||||
@@ -189,9 +187,10 @@ def _build_explanation(
|
||||
msg = "Bevorzugt" if type_weight > 1.0 else "Leicht abgewertet"
|
||||
reasons.append(Reason(kind="type", message=f"{msg} aufgrund des Typs '{note_type}'.", score_impact=(sem_w * semantic_score * (type_weight - 1.0))))
|
||||
|
||||
# WP-22: Status Grund hinzufügen
|
||||
if status_mult != 1.0:
|
||||
msg = "Status-Bonus" if status_mult > 1.0 else "Status-Malus"
|
||||
reasons.append(Reason(kind="lifecycle", message=f"{msg} ({payload.get('status')}).", score_impact=0.0))
|
||||
reasons.append(Reason(kind="lifecycle", message=f"{msg} ({payload.get('status', 'unknown')}).", score_impact=0.0))
|
||||
|
||||
if subgraph and node_key and edge_bonus > 0:
|
||||
if hasattr(subgraph, "get_outgoing_edges"):
|
||||
@@ -226,7 +225,7 @@ def _build_explanation(
|
||||
|
||||
|
||||
def _extract_expand_options(req: QueryRequest) -> Tuple[int, List[str] | None]:
|
||||
"""Extrahiert depth und edge_types."""
|
||||
"""Extrahiert depth und edge_types für die Graph-Expansion."""
|
||||
expand = getattr(req, "expand", None)
|
||||
if not expand:
|
||||
return 0, None
|
||||
@@ -259,7 +258,7 @@ def _build_hits_from_semantic(
|
||||
explain: bool = False,
|
||||
dynamic_edge_boosts: Dict[str, float] = None
|
||||
) -> QueryResponse:
|
||||
"""Baut strukturierte QueryHits."""
|
||||
"""Baut strukturierte QueryHits basierend auf den berechneten Scores."""
|
||||
t0 = time.time()
|
||||
enriched: List[Tuple[str, float, Dict[str, Any], float, float, float]] = []
|
||||
|
||||
@@ -307,7 +306,7 @@ def _build_hits_from_semantic(
|
||||
|
||||
results.append(QueryHit(
|
||||
node_id=str(pid),
|
||||
note_id=payload.get("note_id"),
|
||||
note_id=payload.get("note_id", "unknown"),
|
||||
semantic_score=float(semantic_score),
|
||||
edge_bonus=edge_bonus,
|
||||
centrality_bonus=cent_bonus,
|
||||
@@ -327,7 +326,7 @@ def _build_hits_from_semantic(
|
||||
|
||||
|
||||
def semantic_retrieve(req: QueryRequest) -> QueryResponse:
|
||||
"""Reiner semantischer Retriever."""
|
||||
"""Reiner semantischer Retriever (WP-02)."""
|
||||
client, prefix = _get_client_and_prefix()
|
||||
vector = _get_query_vector(req)
|
||||
top_k = req.top_k or get_settings().RETRIEVER_TOP_K
|
||||
@@ -337,7 +336,7 @@ def semantic_retrieve(req: QueryRequest) -> QueryResponse:
|
||||
|
||||
|
||||
def hybrid_retrieve(req: QueryRequest) -> QueryResponse:
|
||||
"""Hybrid-Retriever: semantische Suche + optionale Edge-Expansion."""
|
||||
"""Hybrid-Retriever: semantische Suche + optionale Edge-Expansion (WP-04a)."""
|
||||
client, prefix = _get_client_and_prefix()
|
||||
if req.query_vector:
|
||||
vector = list(req.query_vector)
|
||||
@@ -349,27 +348,28 @@ def hybrid_retrieve(req: QueryRequest) -> QueryResponse:
|
||||
|
||||
depth, edge_types = _extract_expand_options(req)
|
||||
|
||||
# WP-22: Dynamic Boosts aus dem Request (vom Router)
|
||||
# WP-22: Dynamic Boosts aus dem Request (vom Router) (Teil C)
|
||||
boost_edges = getattr(req, "boost_edges", {})
|
||||
|
||||
subgraph: ga.Subgraph | None = None
|
||||
if depth and depth > 0:
|
||||
seed_ids: List[str] = []
|
||||
for _pid, _score, payload in hits:
|
||||
key = payload.get("chunk_id") or payload.get("note_id")
|
||||
key = payload.get("note_id")
|
||||
if key and key not in seed_ids:
|
||||
seed_ids.append(key)
|
||||
if seed_ids:
|
||||
try:
|
||||
# Hier könnten wir boost_edges auch an expand übergeben, wenn ga.expand es unterstützt
|
||||
# Subgraph laden
|
||||
subgraph = ga.expand(client, prefix, seed_ids, depth=depth, edge_types=edge_types)
|
||||
|
||||
# Manuelles Boosten der Kantengewichte im Graphen falls aktiv
|
||||
# --- WP-22: Kanten-Boosts im RAM-Graphen anwenden ---
|
||||
# Dies manipuliert die Gewichte im Graphen, bevor der 'edge_bonus' berechnet wird.
|
||||
if boost_edges and subgraph and hasattr(subgraph, "graph"):
|
||||
for u, v, data in subgraph.graph.edges(data=True):
|
||||
k = data.get("kind")
|
||||
if k in boost_edges:
|
||||
# Gewicht erhöhen für diesen Query-Kontext
|
||||
# Gewicht multiplizieren (z.B. caused_by * 3.0)
|
||||
data["weight"] = data.get("weight", 1.0) * boost_edges[k]
|
||||
|
||||
except Exception:
|
||||
@@ -387,7 +387,7 @@ def hybrid_retrieve(req: QueryRequest) -> QueryResponse:
|
||||
|
||||
class Retriever:
|
||||
"""
|
||||
Wrapper-Klasse für WP-05 (Chat).
|
||||
Wrapper-Klasse für Suchoperationen.
|
||||
"""
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
Reference in new issue
Block a user