Dateien nach "app/core" hochladen
All checks were successful
Deploy mindnet to llm-node / deploy (push) Successful in 3s
All checks were successful
Deploy mindnet to llm-node / deploy (push) Successful in 3s
This commit is contained in:
parent
948d6f4b47
commit
2a1c62aeed
|
|
@ -3,16 +3,14 @@
|
||||||
"""
|
"""
|
||||||
app/core/chunk_payload.py — Mindnet V2 (compat)
|
app/core/chunk_payload.py — Mindnet V2 (compat)
|
||||||
|
|
||||||
Ziel:
|
Ziele:
|
||||||
- Bewahrt bestehendes Verhalten (index, chunk_profile, retriever_weight, etc.)
|
- Bewahrt bestehendes Verhalten (index, chunk_profile, retriever_weight, etc.)
|
||||||
- Ergänzt optionale Denormalisierung: `tags` aus der Note‑FM auch auf Chunks
|
- Denormalisiert optional `tags` aus der Note‑FM auf Chunks
|
||||||
- Fügt Aliase für die Chunk‑Nummer hinzu: `ord` (v2‑Schema), `chunk_num`, `Chunk_Nummer`
|
- Fügt Aliase für die Chunk‑Nummer hinzu: `ord` (v2‑Schema), `chunk_num`, `Chunk_Nummer`
|
||||||
(Letztere ist rein UI/Filter-freundlich für deine bestehenden Indizes mit dt. Keys.)
|
- **Kompatibilität:** akzeptiert sowohl `path_arg` (positional) als auch `file_path` (keyword)
|
||||||
|
|
||||||
Hinweis:
|
Hinweis:
|
||||||
- `edge_defaults` gehören konzeptionell zur *Note* (Regelmenge des Quelltyps)
|
- `edge_defaults` sind Note‑Regeln (Typ) und werden nicht pro Chunk gespiegelt.
|
||||||
und werden nicht pro Chunk repliziert. Falls gewünscht, kann das optional
|
|
||||||
ergänzt werden – aktuell **nicht** gesetzt, siehe Design-Kommentar im PR.
|
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
|
@ -53,23 +51,31 @@ def _load_types_config(types_cfg_explicit: Optional[dict] = None) -> dict:
|
||||||
"""Types-Registry *optional* einspeisen (bereits geparst), sonst lazy-laden vermeiden."""
|
"""Types-Registry *optional* einspeisen (bereits geparst), sonst lazy-laden vermeiden."""
|
||||||
return types_cfg_explicit or {}
|
return types_cfg_explicit or {}
|
||||||
|
|
||||||
def _text_from_note(note: Dict[str, Any], path: str) -> str:
|
def _text_from_note(note: Dict[str, Any]) -> str:
|
||||||
# Erwartete Inputs (siehe parser.py / import_markdown.py):
|
# Erwartete Inputs (siehe parser.py / import_markdown.py):
|
||||||
# note["body"] oder note["text"]; Fallback leerer String
|
# note["body"] oder note["text"]; Fallback leerer String
|
||||||
return note.get("body") or note.get("text") or ""
|
return note.get("body") or note.get("text") or ""
|
||||||
|
|
||||||
def _iter_chunks(note: Dict[str, Any], chunk_profile: str, fulltext: str) -> List[Dict[str, Any]]:
|
def _iter_chunks(note: Dict[str, Any], chunk_profile: str, fulltext: str) -> List[Dict[str, Any]]:
|
||||||
"""Nutze bestehenden assemble_chunks(note_id, body, type) Pfad, keine Doppel-Logik hier."""
|
"""Nutze bestehenden assemble_chunks(note_id, body, type)."""
|
||||||
note_id = note.get("id") or (note.get("frontmatter") or {}).get("id")
|
note_id = note.get("id") or (note.get("frontmatter") or {}).get("id")
|
||||||
ntype = (note.get("frontmatter") or {}).get("type") or note.get("type") or "note"
|
ntype = (note.get("frontmatter") or {}).get("type") or note.get("type") or "note"
|
||||||
# assemble_chunks liefert Liste von Dicts mit mindestens {"index","text"} (v1)
|
# assemble_chunks liefert Liste von Dicts mit mindestens {"index","text"} (v1)
|
||||||
return assemble_chunks(note_id, fulltext, ntype)
|
return assemble_chunks(note_id, fulltext, ntype)
|
||||||
|
|
||||||
def make_chunk_payloads(note: Any, path_arg: Optional[str], chunks_from_chunker: Optional[List[Dict[str, Any]]] = None, *, note_text: Optional[str] = None, types_cfg: Optional[dict] = None) -> List[Dict[str, Any]]:
|
def make_chunk_payloads(
|
||||||
|
note: Any,
|
||||||
|
path_arg: Optional[str] = None,
|
||||||
|
chunks_from_chunker: Optional[List[Dict[str, Any]]] = None,
|
||||||
|
*,
|
||||||
|
file_path: Optional[str] = None,
|
||||||
|
note_text: Optional[str] = None,
|
||||||
|
types_cfg: Optional[dict] = None,
|
||||||
|
) -> List[Dict[str, Any]]:
|
||||||
"""
|
"""
|
||||||
Erzeugt Chunk-Payloads. Erwartet:
|
Erzeugt Chunk-Payloads. Erwartet:
|
||||||
- `note`: Normalisierte Note-Struktur (inkl. frontmatter)
|
- `note`: Normalisierte Note-Struktur (inkl. frontmatter)
|
||||||
- `path_arg`: Pfad der Note
|
- `path_arg` oder `file_path`: Pfad der Note
|
||||||
- `chunks_from_chunker`: optional: Ergebnis von assemble_chunks (sonst wird intern erzeugt)
|
- `chunks_from_chunker`: optional: Ergebnis von assemble_chunks (sonst wird intern erzeugt)
|
||||||
|
|
||||||
Rückgabe: Liste aus Payload-Dicts, jedes mit mind.:
|
Rückgabe: Liste aus Payload-Dicts, jedes mit mind.:
|
||||||
|
|
@ -95,7 +101,8 @@ def make_chunk_payloads(note: Any, path_arg: Optional[str], chunks_from_chunker:
|
||||||
|
|
||||||
note_id = n.get("note_id") or n.get("id") or fm.get("id")
|
note_id = n.get("note_id") or n.get("id") or fm.get("id")
|
||||||
title = n.get("title") or fm.get("title") or ""
|
title = n.get("title") or fm.get("title") or ""
|
||||||
path = n.get("path") or path_arg
|
# Pfad-Auflösung: Priorität file_path > note['path'] > path_arg
|
||||||
|
path = file_path or n.get("path") or path_arg
|
||||||
if isinstance(path, pathlib.Path):
|
if isinstance(path, pathlib.Path):
|
||||||
path = str(path)
|
path = str(path)
|
||||||
path = path or "" # garantiert vorhanden
|
path = path or "" # garantiert vorhanden
|
||||||
|
|
@ -105,7 +112,7 @@ def make_chunk_payloads(note: Any, path_arg: Optional[str], chunks_from_chunker:
|
||||||
tags_list = _ensure_list(tags) if tags else []
|
tags_list = _ensure_list(tags) if tags else []
|
||||||
|
|
||||||
# Quelltext
|
# Quelltext
|
||||||
fulltext = note_text if isinstance(note_text, str) else _text_from_note(n, path)
|
fulltext = note_text if isinstance(note_text, str) else _text_from_note(n)
|
||||||
|
|
||||||
# Chunks besorgen
|
# Chunks besorgen
|
||||||
chunks = chunks_from_chunker if isinstance(chunks_from_chunker, list) else _iter_chunks(n, chunk_profile, fulltext)
|
chunks = chunks_from_chunker if isinstance(chunks_from_chunker, list) else _iter_chunks(n, chunk_profile, fulltext)
|
||||||
|
|
@ -127,11 +134,11 @@ def make_chunk_payloads(note: Any, path_arg: Optional[str], chunks_from_chunker:
|
||||||
"index": idx,
|
"index": idx,
|
||||||
"ord": idx, # Alias für v2‑Schema
|
"ord": idx, # Alias für v2‑Schema
|
||||||
"chunk_num": idx, # neutraler Alias
|
"chunk_num": idx, # neutraler Alias
|
||||||
"Chunk_Nummer": idx, # deutschsprachiger Alias (zur Filter‑Kompatibilität)
|
"Chunk_Nummer": idx, # deutschsprachiger Alias
|
||||||
"title": title,
|
"title": title,
|
||||||
"type": note_type,
|
"type": note_type,
|
||||||
"path": path, # garantiert vorhanden
|
"path": path, # garantiert vorhanden
|
||||||
"text": text, # nie leer, sonst kein Chunk
|
"text": text, # nie leer
|
||||||
"retriever_weight": retriever_weight,
|
"retriever_weight": retriever_weight,
|
||||||
"chunk_profile": chunk_profile,
|
"chunk_profile": chunk_profile,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user