herstellung vollständiger Kompaitibilität

This commit is contained in:
Lars committed 2025-12-27 13:20:37 +01:00
1 parent cfcaa926cd
commit f08a331bc6
3 files changed
+99 -60

No files matched your search

+43 -23
View File
@@ -1,52 +1,68 @@
"""
FILE: app/core/ingestion/ingestion_chunk_payload.py
DESCRIPTION: Baut das JSON-Objekt für 'mindnet_chunks'.
Fix v2.4.1: Behebt AttributeError bei Zugriff auf Chunk-Objekte.
VERSION: 2.4.1
Fix v2.4.2: Audit-Check (Cleanup pop, Config-Resolution Hierarchie).
VERSION: 2.4.2
STATUS: Active
"""
from __future__ import annotations
from typing import Any, Dict, List, Optional
# ---------------------------------------------------------------------------
# Resolution Helpers (Audited)
# ---------------------------------------------------------------------------
def _as_list(x):
if x is None: return []
return x if isinstance(x, list) else [x]
def make_chunk_payloads(note: Dict[str, Any],
note_path: str,
chunks_from_chunker: List[Any],
**kwargs) -> List[Dict[str, Any]]:
"""
Erstellt die Payloads für die Chunks eines Dokuments.
Robust gegenüber Chunk-Objekten (Dataclasses) und Dictionaries.
"""
# Frontmatter Extraktion
if isinstance(note, dict) and "frontmatter" in note:
fm = note["frontmatter"]
else:
fm = note or {}
def _resolve_val(note_type: str, reg: dict, key: str, default: Any) -> Any:
"""Hierarchische Suche: Type > Default."""
types = reg.get("types", {})
if isinstance(types, dict):
t_cfg = types.get(note_type, {})
if isinstance(t_cfg, dict):
val = t_cfg.get(key) or t_cfg.get(key.replace("ing", "")) # chunking_ vs chunk_
if val is not None: return val
defs = reg.get("defaults", {}) or reg.get("global", {})
if isinstance(defs, dict):
val = defs.get(key) or defs.get(key.replace("ing", ""))
if val is not None: return val
return default
# ---------------------------------------------------------------------------
# Haupt-API
# ---------------------------------------------------------------------------
def make_chunk_payloads(note: Dict[str, Any], note_path: str, chunks_from_chunker: List[Any], **kwargs) -> List[Dict[str, Any]]:
"""Erstellt die Payloads für die Chunks inklusive Audit-Resolution."""
if isinstance(note, dict) and "frontmatter" in note: fm = note["frontmatter"]
else: fm = note or {}
reg = kwargs.get("types_cfg") or {}
note_type = fm.get("type") or "concept"
title = fm.get("title") or fm.get("id") or "Untitled"
tags = _as_list(fm.get("tags") or [])
cp = fm.get("chunking_profile") or fm.get("chunk_profile") or "sliding_standard"
rw = float(fm.get("retriever_weight", 1.0))
# Audit: Resolution Hierarchie
cp = fm.get("chunking_profile") or fm.get("chunk_profile")
if not cp: cp = _resolve_val(note_type, reg, "chunking_profile", "sliding_standard")
rw = fm.get("retriever_weight")
if rw is None: rw = _resolve_val(note_type, reg, "retriever_weight", 1.0)
try: rw = float(rw)
except: rw = 1.0
out: List[Dict[str, Any]] = []
for idx, ch in enumerate(chunks_from_chunker):
# Dynamische Extraktion basierend auf Typ (Objekt vs Dict)
is_dict = isinstance(ch, dict)
cid = getattr(ch, "id", None) if not is_dict else ch.get("id")
nid = getattr(ch, "note_id", None) if not is_dict else ch.get("note_id")
index = getattr(ch, "index", idx) if not is_dict else ch.get("index", idx)
text = getattr(ch, "text", "") if not is_dict else ch.get("text", "")
window = getattr(ch, "window", text) if not is_dict else ch.get("window", text)
prev_id = getattr(ch, "neighbors_prev", None) if not is_dict else ch.get("neighbors_prev")
next_id = getattr(ch, "neighbors_next", None) if not is_dict else ch.get("neighbors_next")
# Korrektur des AttributeError: Nutzt getattr für Objekte, .get für Dicts
section = getattr(ch, "section_title", "") if not is_dict else ch.get("section", "")
pl: Dict[str, Any] = {
@@ -67,6 +83,10 @@ def make_chunk_payloads(note: Dict[str, Any],
"retriever_weight": rw,
"chunk_profile": cp
}
out.append(pl)
# Audit: Cleanup Pop (Alias Felder entfernen)
for alias in ("chunk_num", "Chunk_Number"):
pl.pop(alias, None)
out.append(pl)
return out