This commit is contained in:
1 parent
23b1cb2966
commit
e9532e8878
30 files changed
+1835
-542
No files matched your search
@@ -1,3 +1,67 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
FILE: scripts/debug_edge_loss.py
|
||||
VERSION: 2.1.0 (2025-12-15)
|
||||
STATUS: Active (Debug-Tool)
|
||||
COMPATIBILITY: v2.9.1 (Post-WP14/WP-15b)
|
||||
|
||||
Zweck:
|
||||
-------
|
||||
Debug-Tool zur Analyse von Edge-Verlust-Problemen bei der Chunk-Verarbeitung.
|
||||
Hilft zu verstehen, warum bestimmte Edges nicht erkannt oder verloren gehen.
|
||||
|
||||
Funktionsweise:
|
||||
---------------
|
||||
1. Analysiert eine einzelne Markdown-Datei
|
||||
2. Führt zwei Analyseschritte durch:
|
||||
a) Pre-Scan: Extrahiert alle Edge-Kandidaten aus dem rohen Text
|
||||
- Wikilinks
|
||||
- Typed Relations
|
||||
- Callout Relations
|
||||
b) Chunk-Analyse:
|
||||
- Erstellt Chunks mit konfigurierbarem Profil
|
||||
- Prüft, welche Edges in jedem Chunk gefunden werden
|
||||
- Vergleicht mit Pre-Scan-Ergebnissen
|
||||
3. Gibt detaillierte Analyse pro Chunk aus
|
||||
|
||||
Ergebnis-Interpretation:
|
||||
------------------------
|
||||
- [1] Globale Kandidaten: Alle Edge-Kandidaten, die im Text vorhanden sind
|
||||
- [2] Chunk-Struktur: Für jeden Chunk:
|
||||
* Section-Pfad
|
||||
* Text-Snippet
|
||||
* Gefundene explizite Kanten (callout:edge, inline:rel)
|
||||
* Warnung, falls Callout im Text vorhanden, aber nicht erkannt
|
||||
|
||||
Verwendung:
|
||||
-----------
|
||||
- Debugging von Edge-Verlust bei Chunk-Grenzen
|
||||
- Validierung der Edge-Extraktion in verschiedenen Chunk-Kontexten
|
||||
- Analyse von Problemen mit Callout-Erkennung
|
||||
|
||||
Hinweise:
|
||||
---------
|
||||
- Asynchrones Skript (nutzt assemble_chunks async API)
|
||||
- Konfigurierbares Chunking-Profil (Standard: sliding_window, 400/600 chars)
|
||||
- Smart Edge Allocation ist standardmäßig deaktiviert für klare Analyse
|
||||
|
||||
Aufruf:
|
||||
-------
|
||||
python3 scripts/debug_edge_loss.py [PFAD_ZUR_DATEI.md]
|
||||
|
||||
Parameter:
|
||||
----------
|
||||
Keine CLI-Parameter. Dateipfad als erstes Argument oder Standard-Pfad.
|
||||
|
||||
Änderungen:
|
||||
-----------
|
||||
v2.1.0 (2025-12-15): Kompatibilität mit WP-14 Modularisierung
|
||||
- Entfernt: _extract_all_edges_from_md (nicht mehr vorhanden)
|
||||
- Ersetzt durch: extract_wikilinks, extract_typed_relations, extract_callout_relations
|
||||
- Chunk-Payload-Struktur angepasst (window, type hinzugefügt)
|
||||
v1.0.0: Erster Release
|
||||
"""
|
||||
import asyncio
|
||||
import os
|
||||
import sys
|
||||
@@ -6,8 +70,10 @@ from pathlib import Path
|
||||
# Pfad-Setup
|
||||
sys.path.insert(0, os.path.abspath("."))
|
||||
|
||||
from app.core.chunking import assemble_chunks, _extract_all_edges_from_md
|
||||
from app.core.chunking import assemble_chunks
|
||||
from app.core.derive_edges import build_edges_for_note
|
||||
from app.core.parser import extract_wikilinks
|
||||
from app.core.graph.graph_extractors import extract_typed_relations, extract_callout_relations
|
||||
|
||||
# Mock für Settings, falls nötig
|
||||
os.environ["MINDNET_LLM_MODEL"] = "phi3:mini"
|
||||
@@ -19,9 +85,25 @@ async def analyze_file(file_path: str):
|
||||
text = f.read()
|
||||
|
||||
# 1. Globale Kandidaten (Was sieht der Pre-Scan?)
|
||||
# Wir simulieren den Aufruf, den der Chunker macht
|
||||
# Wir extrahieren alle Edge-Kandidaten aus dem Text
|
||||
note_id = Path(file_path).stem
|
||||
candidates = _extract_all_edges_from_md(text, note_id, "concept")
|
||||
candidates = []
|
||||
|
||||
# Wikilinks extrahieren
|
||||
wikilinks = extract_wikilinks(text)
|
||||
for wl in wikilinks:
|
||||
candidates.append(f"wikilink:{wl}")
|
||||
|
||||
# Typed Relations extrahieren
|
||||
typed_rels, _ = extract_typed_relations(text)
|
||||
for kind, target in typed_rels:
|
||||
candidates.append(f"typed:{kind}:{target}")
|
||||
|
||||
# Callout Relations extrahieren
|
||||
callout_rels, _ = extract_callout_relations(text)
|
||||
for kind, target in callout_rels:
|
||||
candidates.append(f"callout:{kind}:{target}")
|
||||
|
||||
print(f"\n[1] Globale Kandidaten (Pre-Scan):")
|
||||
for c in candidates:
|
||||
print(f" - {c}")
|
||||
@@ -45,7 +127,12 @@ async def analyze_file(file_path: str):
|
||||
|
||||
# Was findet derive_edges in diesem rohen Chunk?
|
||||
# Wir simulieren das Payload-Dict, das derive_edges erwartet
|
||||
chunk_pl = {"text": chunk.text, "window": chunk.window, "chunk_id": chunk.id}
|
||||
chunk_pl = {
|
||||
"text": chunk.text,
|
||||
"window": chunk.window or chunk.text,
|
||||
"chunk_id": chunk.id,
|
||||
"type": "concept"
|
||||
}
|
||||
edges = build_edges_for_note(note_id, [chunk_pl])
|
||||
|
||||
found_explicitly = [f"{e['kind']}:{e.get('target_id')}" for e in edges if e['rule_id'] in ['callout:edge', 'inline:rel']]
|
||||
|
||||
Reference in new issue
Block a user