Update graph_utils.py and ingestion_processor.py to versions 1.2.0 and 3.1.9 respectively: Transition to deterministic UUIDs for edge ID generation to ensure Qdrant compatibility and prevent HTTP 400 errors. Enhance ID validation and streamline edge processing logic to improve robustness and prevent collisions with known system types. Adjust versioning and documentation accordingly.

This commit is contained in:
Lars committed 2026-01-09 21:46:47 +01:00
1 parent 72cf71fa87
commit 7ed82ad82e
2 files changed
+40 -93

No files matched your search

+8 -12
View File
@@ -2,12 +2,13 @@
FILE: app/core/graph/graph_utils.py
DESCRIPTION: Basale Werkzeuge, ID-Generierung und Provenance-Konfiguration für den Graphen.
WP-24c: Integration der EdgeRegistry für dynamische Topologie-Defaults.
AUDIT: Erweitert um parse_link_target für sauberes Section-Splitting.
VERSION: 1.1.0 (WP-24c: Dynamic Topology Implementation)
FIX v1.2.0: Umstellung auf deterministische UUIDs (Qdrant Kompatibilität).
VERSION: 1.2.0
STATUS: Active
"""
import os
import hashlib
import uuid
import logging
from typing import Iterable, List, Optional, Set, Any, Tuple
@@ -52,10 +53,8 @@ def _dedupe_seq(seq: Iterable[str]) -> List[str]:
def _mk_edge_id(kind: str, s: str, t: str, scope: str, rule_id: Optional[str] = None, variant: Optional[str] = None) -> str:
"""
Erzeugt eine deterministische 12-Byte ID mittels BLAKE2s.
WP-Fix: 'variant' (z.B. Section) fließt in den Hash ein, um mehrere Kanten
zum gleichen Target-Node (aber unterschiedlichen Abschnitten) zu unterscheiden.
Erzeugt eine deterministische UUID v5-konforme ID für Qdrant.
Behebt den 'HTTP 400 Bad Request', indem ein valides UUID-Format geliefert wird.
"""
base = f"{kind}:{s}->{t}#{scope}"
if rule_id:
@@ -63,7 +62,9 @@ def _mk_edge_id(kind: str, s: str, t: str, scope: str, rule_id: Optional[str] =
if variant:
base += f"|{variant}"
return hashlib.blake2s(base.encode("utf-8"), digest_size=12).hexdigest()
# Wir erzeugen einen 16-Byte Hash (128 Bit) für die UUID-Konvertierung
hash_bytes = hashlib.blake2s(base.encode("utf-8"), digest_size=16).digest()
return str(uuid.UUID(bytes=hash_bytes))
def _edge(kind: str, scope: str, source_id: str, target_id: str, note_id: str, extra: Optional[dict] = None) -> dict:
"""Konstruiert ein Kanten-Payload für Qdrant."""
@@ -108,23 +109,18 @@ def get_edge_defaults_for(note_type: Optional[str], reg: dict) -> List[str]:
WP-24c: Ermittelt Standard-Kanten (Typical Edges) für einen Notiz-Typ.
Nutzt die EdgeRegistry (graph_schema.md) als primäre Quelle.
"""
# 1. Dynamische Abfrage über die neue Topologie-Engine (WP-24c)
# Behebt das Audit-Problem 1a/1b: Suche in graph_schema.md statt types.yaml
if note_type:
topology = edge_registry.get_topology_info(note_type, "any")
typical = topology.get("typical", [])
if typical:
return typical
# 2. Legacy-Fallback: Suche in der geladenen Registry (types.yaml)
# Sichert 100% Rückwärtskompatibilität, falls Reste in types.yaml verblieben sind.
types_map = reg.get("types", reg) if isinstance(reg, dict) else {}
if note_type and isinstance(types_map, dict):
t = types_map.get(note_type)
if isinstance(t, dict) and isinstance(t.get("edge_defaults"), list):
return [str(x) for x in t["edge_defaults"] if isinstance(x, str)]
# 3. Globaler Default-Fallback aus der Registry
for key in ("defaults", "default", "global"):
v = reg.get(key)
if isinstance(v, dict) and isinstance(v.get("edge_defaults"), list):