Aktualisierung des Chunking-Parsers zur Verbesserung der Blockverarbeitung und Beschreibung. Anpassungen an der atomaren Sektions-Chunking-Strategie mit optimierter Token-Schätzung und neuen Hilfsfunktionen zur besseren Handhabung von großen Sektionen.
This commit is contained in:
1 parent
b1a897e51c
commit
96b4f65cd1
2 files changed
+55
-68
No files matched your search
@@ -1,7 +1,7 @@
|
||||
"""
|
||||
FILE: app/core/chunking/chunking_parser.py
|
||||
DESCRIPTION: Zerlegt Markdown in logische Blöcke. Hält H1-Überschriften im Stream
|
||||
und optimiert die Block-Trennung für atomares Sektions-Chunking.
|
||||
DESCRIPTION: Zerlegt Markdown in logische Einheiten (RawBlocks).
|
||||
Hält H1-Überschriften im Inhalts-Stream.
|
||||
"""
|
||||
import re
|
||||
from typing import List, Tuple, Set
|
||||
@@ -15,7 +15,6 @@ def split_sentences(text: str) -> list[str]:
|
||||
"""Teilt Text in Sätze auf unter Berücksichtigung deutscher Interpunktion."""
|
||||
text = _WS.sub(' ', text.strip())
|
||||
if not text: return []
|
||||
# Splittet bei Satzzeichen, gefolgt von Leerzeichen und Großbuchstaben
|
||||
return [p.strip() for p in _SENT_SPLIT.split(text) if p.strip()]
|
||||
|
||||
def parse_blocks(md_text: str) -> Tuple[List[RawBlock], str]:
|
||||
@@ -28,7 +27,7 @@ def parse_blocks(md_text: str) -> Tuple[List[RawBlock], str]:
|
||||
# Frontmatter entfernen
|
||||
fm, text_without_fm = extract_frontmatter_from_text(md_text)
|
||||
|
||||
# H1 für Note-Metadaten extrahieren
|
||||
# H1 für Note-Titel extrahieren
|
||||
h1_match = re.search(r'^#\s+(.*)', text_without_fm, re.MULTILINE)
|
||||
if h1_match:
|
||||
h1_title = h1_match.group(1).strip()
|
||||
@@ -42,7 +41,7 @@ def parse_blocks(md_text: str) -> Tuple[List[RawBlock], str]:
|
||||
# Heading-Erkennung (H1 bis H6)
|
||||
heading_match = re.match(r'^(#{1,6})\s+(.*)', stripped)
|
||||
if heading_match:
|
||||
# Vorherigen Block abschließen
|
||||
# Vorherigen Text-Block abschließen
|
||||
if buffer:
|
||||
content = "\n".join(buffer).strip()
|
||||
if content:
|
||||
@@ -52,7 +51,7 @@ def parse_blocks(md_text: str) -> Tuple[List[RawBlock], str]:
|
||||
level = len(heading_match.group(1))
|
||||
title = heading_match.group(2).strip()
|
||||
|
||||
# Update der Pfad-Metadaten für die folgenden Blöcke
|
||||
# Pfad- und Titel-Update für die Metadaten der folgenden Blöcke
|
||||
if level == 1:
|
||||
current_section_title = title
|
||||
section_path = "/"
|
||||
@@ -60,11 +59,11 @@ def parse_blocks(md_text: str) -> Tuple[List[RawBlock], str]:
|
||||
current_section_title = title
|
||||
section_path = f"/{current_section_title}"
|
||||
|
||||
# Die Überschrift als regulären Block hinzufügen (Fix: H1 bleibt im Text)
|
||||
# Die Überschrift selbst als Block hinzufügen
|
||||
blocks.append(RawBlock("heading", stripped, level, section_path, current_section_title))
|
||||
continue
|
||||
|
||||
# Trenner (---) oder Leerzeilen beenden Blöcke, außer in Callouts
|
||||
# Trenner oder Leerzeilen beenden Blöcke, außer innerhalb von Callouts
|
||||
if (not stripped or stripped == "---") and not line.startswith('>'):
|
||||
if buffer:
|
||||
content = "\n".join(buffer).strip()
|
||||
@@ -76,7 +75,6 @@ def parse_blocks(md_text: str) -> Tuple[List[RawBlock], str]:
|
||||
else:
|
||||
buffer.append(line)
|
||||
|
||||
# Letzten Puffer leeren
|
||||
if buffer:
|
||||
content = "\n".join(buffer).strip()
|
||||
if content:
|
||||
@@ -87,14 +85,12 @@ def parse_blocks(md_text: str) -> Tuple[List[RawBlock], str]:
|
||||
def parse_edges_robust(text: str) -> Set[str]:
|
||||
"""Extrahiert Kanten-Kandidaten aus Wikilinks und Callouts."""
|
||||
found_edges = set()
|
||||
# 1. Wikilinks [[rel:kind|target]]
|
||||
inlines = re.findall(r'\[\[rel:([^\|\]]+)\|?([^\]]*)\]\]', text)
|
||||
for kind, target in inlines:
|
||||
k = kind.strip().lower()
|
||||
t = target.strip()
|
||||
if k and t: found_edges.add(f"{k}:{t}")
|
||||
|
||||
# 2. Callout Edges > [!edge] kind
|
||||
lines = text.split('\n')
|
||||
current_edge_type = None
|
||||
for line in lines:
|
||||
|
||||
Reference in new issue
Block a user