app/core/derive_edges.py aktualisiert
Some checks failed
Deploy mindnet to llm-node / deploy (push) Failing after 1s

This commit is contained in:
Lars 2025-09-05 11:03:58 +02:00
parent da2bbf72a6
commit 38fd7420ff

View File

@ -4,20 +4,26 @@
Name: app/core/derive_edges.py
Version: v1.1.0 (2025-09-05)
Kurzbeschreibung:
Leitet Edges aus Wikilinks ([[...]]) ab.
- Unterstützt Auflösung über note_id, Title-Slug, File-Slug.
- Erzeugt Edges:
* "references" (Note->Note) + "backlink" (inverse)
* "references_at" (Chunk->Note) mit seq = chunk_index
- **NEU**: pro Match ein Occurrence-Zähler 'occ' für eindeutige Edge-IDs.
Kurzbeschreibung
Leitet Edges aus Wikilinks ([[]]) ab und löst Zielnoten robust auf.
Erzeugt:
- "references" (Note -> Note) mit seq="body", pro Match eine eigene Occurrence 'occ'
- "backlink" (inverse zu "references", gleiche seq/occ)
- "references_at" (Chunk -> Note) mit seq=<chunk_index> und eigener 'occ' je Match
Kompatibilität:
- Vorherige Payload-Felder bleiben erhalten.
- Zusätzliche Felder: 'seq' für Volltext ("body"), 'occ' überall.
Aufruf
from app.core.derive_edges import build_note_index, derive_wikilink_edges
Changelog:
v1.1.0: 'occ' eingeführt; 'references' erhalten jetzt seq="body".
Parameter / Felder
- note_payload: {"note_id","title","path","fulltext": <body> , }
- chunks_payloads: [{"chunk_id","text",}, ]
- note_index: build_note_index([...]) -> (by_id, by_slug, by_file_slug)
Kompatibilität
- Rückwärtskompatible Payload-Felder, nur erweitert um 'seq' und 'occ'.
Changelog
v1.1.0: Occurrence-Zählung ('occ') je Match; 'seq="body"' für references.
"""
from __future__ import annotations
@ -85,7 +91,7 @@ def derive_wikilink_edges(note_payload: dict, chunks_payloads: List[dict], note_
e.update(extra)
return e
# Links im Volltext (gesamter Body)
# Volltext (Note-Ebene)
fulltext = note_payload.get("fulltext") or note_payload.get("body") or ""
if fulltext:
for k, m in enumerate(WIKILINK_RE.finditer(fulltext), start=1):
@ -100,7 +106,7 @@ def derive_wikilink_edges(note_payload: dict, chunks_payloads: List[dict], note_
extra["target_label"] = raw_target
edges.append(_make_edge("references", source_note_id, raw_target, seq="body", occ=k, extra=extra))
# Links in Chunks (wenn übergeben)
# Chunks (Chunk-Ebene)
for i, ch in enumerate(chunks_payloads, start=1):
txt = ch.get("text") or ch.get("content") or ""
if not txt: