diff --git a/app/core/chunk_payload.py b/app/core/chunk_payload.py new file mode 100644 index 0000000..dec7c2b --- /dev/null +++ b/app/core/chunk_payload.py @@ -0,0 +1,37 @@ +from __future__ import annotations +from typing import Dict, List +from .chunker import Chunk +from .parser import extract_wikilinks + +def make_chunk_payloads(note_meta: Dict, path: str, chunks: List[Chunk]) -> List[Dict]: + res = [] + for ch in chunks: + wikilinks = extract_wikilinks(ch.text) + payload = { + "id": ch.id, + "note_id": note_meta["id"], + "note_title": note_meta["title"], + "chunk_index": ch.index, + "char_start": ch.char_start, + "char_end": ch.char_end, + "token_count": ch.token_count, + "type": note_meta.get("type"), + "area": note_meta.get("area"), + "project": note_meta.get("project"), + "tags": note_meta.get("tags", []), + "section_title": ch.section_title, + "section_path": ch.section_path, + "lang": note_meta.get("lang"), + "wikilinks": wikilinks, + "external_links": [], # (optional später ergänzen) + "references": [{"target_id": w, "kind": "wikilink"} for w in wikilinks], + "neighbors": { + "prev": ch.neighbors_prev, + "next": ch.neighbors_next + }, + "path": path, + } + # None/Leere bereinigen + payload = {k: v for k, v in payload.items() if v not in (None, [], {})} + res.append(payload) + return res