Implement Phase 3 Agentic Edge Validation in ingestion_processor.py and related documentation updates

Introduce a new method for persisting rejected edges for audit purposes, enhancing traceability and validation logic. Update the decision engine to utilize a generic fallback template for improved error handling during LLM validation. Revise documentation across multiple files to reflect the new versioning, context, and features related to Phase 3 validation, including automatic mirror edges and note-scope zones. This update ensures better graph integrity and validation accuracy in the ingestion process.
This commit is contained in:
Lars committed 2026-01-12 07:45:54 +01:00
1 parent b19f91c3ee
commit 742792770c
18 files changed
+1110 -119

No files matched your search

+51
View File
@@ -91,6 +91,55 @@ class IngestionService:
except Exception as e:
logger.warning(f"DB initialization warning: {e}")
def _persist_rejected_edges(self, note_id: str, rejected_edges: List[Dict[str, Any]]) -> None:
"""
WP-24c v4.5.9: Persistiert abgelehnte Kanten für Audit-Zwecke.
Schreibt rejected_edges in eine JSONL-Datei im _system Ordner oder logs/rejected_edges.log.
Dies ermöglicht die Analyse der Ablehnungsgründe und Verbesserung der Validierungs-Logik.
Args:
note_id: ID der Note, zu der die abgelehnten Kanten gehören
rejected_edges: Liste von abgelehnten Edge-Dicts
"""
if not rejected_edges:
return
import json
import os
from datetime import datetime
# WP-24c v4.5.9: Erstelle Log-Verzeichnis falls nicht vorhanden
log_dir = "logs"
if not os.path.exists(log_dir):
os.makedirs(log_dir)
log_file = os.path.join(log_dir, "rejected_edges.log")
# WP-24c v4.5.9: Schreibe als JSONL (eine Kante pro Zeile)
try:
with open(log_file, "a", encoding="utf-8") as f:
for edge in rejected_edges:
log_entry = {
"timestamp": datetime.now().isoformat(),
"note_id": note_id,
"edge": {
"kind": edge.get("kind", "unknown"),
"source_id": edge.get("source_id", "unknown"),
"target_id": edge.get("target_id") or edge.get("to", "unknown"),
"scope": edge.get("scope", "unknown"),
"provenance": edge.get("provenance", "unknown"),
"rule_id": edge.get("rule_id", "unknown"),
"confidence": edge.get("confidence", 0.0),
"target_section": edge.get("target_section")
}
}
f.write(json.dumps(log_entry, ensure_ascii=False) + "\n")
logger.debug(f"📝 [AUDIT] {len(rejected_edges)} abgelehnte Kanten für '{note_id}' in {log_file} gespeichert")
except Exception as e:
logger.error(f"❌ [AUDIT] Fehler beim Speichern der rejected_edges: {e}")
def _is_valid_id(self, text: Optional[str]) -> bool:
"""WP-24c: Prüft IDs auf fachliche Validität (Ghost-ID Schutz)."""
if not text or not isinstance(text, str) or len(text.strip()) < 2:
@@ -367,8 +416,10 @@ class IngestionService:
validated_edges.append(e)
# WP-24c v4.5.8: Phase 3 abgeschlossen - rejected_edges werden NICHT weiterverarbeitet
# WP-24c v4.5.9: Persistierung von rejected_edges für Audit-Zwecke
if rejected_edges:
logger.info(f"🚫 [PHASE 3] {len(rejected_edges)} Kanten abgelehnt und werden nicht in die DB geschrieben")
self._persist_rejected_edges(note_id, rejected_edges)
# WP-24c v4.5.8: Verwende validated_edges statt raw_edges für weitere Verarbeitung
# Nur verified Kanten (ohne candidate: Präfix) werden in Phase 2 (Symmetrie) verarbeitet