Optimierung des Chunking-Parsers zur Unterstützung atomares Chunking und verbesserte Block-Trennung. Anpassungen an der Sektions-Chunking-Strategie zur Wahrung von Sektionsgrenzen und Vermeidung von Überhängen.

This commit is contained in:
Lars committed 2025-12-29 20:57:07 +01:00
1 parent 7eba1fb487
commit 1b40e29f40
2 files changed
+36 -19

No files matched your search

+8 -4
View File
@@ -1,6 +1,7 @@
"""
FILE: app/core/chunking/chunking_parser.py
DESCRIPTION: Zerlegt Markdown in Blöcke. Hält H1-Überschriften im Stream.
DESCRIPTION: Zerlegt Markdown in Blöcke. Hält H1-Überschriften im Stream
und optimiert die Block-Trennung für atomares Chunking.
"""
import re
from typing import List, Tuple, Set
@@ -24,7 +25,8 @@ def parse_blocks(md_text: str) -> Tuple[List[RawBlock], str]:
# H1 für Note-Titel extrahieren (Metadaten)
h1_match = re.search(r'^#\s+(.*)', text_without_fm, re.MULTILINE)
if h1_match: h1_title = h1_match.group(1).strip()
if h1_match:
h1_title = h1_match.group(1).strip()
lines = text_without_fm.split('\n')
buffer = []
@@ -45,7 +47,7 @@ def parse_blocks(md_text: str) -> Tuple[List[RawBlock], str]:
level = len(heading_match.group(1))
title = heading_match.group(2).strip()
# Pfad- und Titel-Update
# Pfad- und Titel-Update für die Metadaten der folgenden Blöcke
if level == 1:
current_section_title = title
section_path = "/"
@@ -53,10 +55,12 @@ def parse_blocks(md_text: str) -> Tuple[List[RawBlock], str]:
current_section_title = title
section_path = f"/{current_section_title}"
# Die Überschrift selbst als Block hinzufügen (Fix: H1 wird nicht mehr gefiltert)
blocks.append(RawBlock("heading", stripped, level, section_path, current_section_title))
continue
if not stripped and not line.startswith('>'): # Leerzeilen (außer in Callouts) trennen Blöcke
# Leerzeilen trennen Blöcke, außer innerhalb von Callouts
if not stripped and not line.startswith('>'):
if buffer:
content = "\n".join(buffer).strip()
if content: