Enhance chunking strategies and graph utilities for section-type transitions and block ID extraction
- Implemented WP-26 v1.1: Section-Type-Wechsel erzwingt Split auch in SMART MODE (Schritt 2) zur Verbesserung der Chunking-Logik. - Updated `parse_link_target` to extract block IDs from section strings, ensuring accurate handling of links with block references. - Added unit tests to validate section-type change behavior and block ID extraction functionality, enhancing overall reliability.
This commit is contained in:
1 parent
af3cc0a254
commit
52fdc425f7
3 files changed
+121
No files matched your search
@@ -191,6 +191,36 @@ def strategy_by_heading(blocks: List[RawBlock], config: Dict[str, Any], note_id:
|
||||
continue
|
||||
|
||||
# FALL B: SMART MODE (Regel 1-3)
|
||||
# WP-26 v1.1: Prüfe auf Section-Type-Wechsel AUCH in Schritt 2
|
||||
# Wenn sich der section_type zwischen current_meta und item ändert, muss gesplittet werden
|
||||
item_section_type = item.get("section_type")
|
||||
current_section_type_meta = current_meta.get("section_type")
|
||||
|
||||
# Section-Type-Wechsel: Von None zu einem Typ ODER von einem Typ zu einem anderen
|
||||
is_section_type_change_step2 = (
|
||||
current_chunk_text and # Es gibt bereits Content
|
||||
(
|
||||
# Wechsel von None zu einem Typ
|
||||
(current_section_type_meta is None and item_section_type is not None) or
|
||||
# Wechsel von einem Typ zu None
|
||||
(current_section_type_meta is not None and item_section_type is None) or
|
||||
# Wechsel zwischen verschiedenen Typen
|
||||
(current_section_type_meta is not None and item_section_type is not None
|
||||
and current_section_type_meta != item_section_type)
|
||||
)
|
||||
)
|
||||
|
||||
if is_section_type_change_step2:
|
||||
# WP-26 v1.1: Section-Type-Wechsel erzwingt Split
|
||||
_emit(current_chunk_text, current_meta["title"], current_meta["path"],
|
||||
current_meta["section_type"], current_meta["block_id"])
|
||||
current_chunk_text = ""
|
||||
# Reset Meta für nächsten Chunk
|
||||
current_meta["title"] = item["meta"].section_title
|
||||
current_meta["path"] = item["meta"].section_path
|
||||
current_meta["section_type"] = item_section_type
|
||||
current_meta["block_id"] = item.get("block_id")
|
||||
|
||||
combined_text = (current_chunk_text + "\n\n" + item_text).strip() if current_chunk_text else item_text
|
||||
combined_est = estimate_tokens(combined_text)
|
||||
|
||||
|
||||
@@ -131,6 +131,12 @@ def parse_link_target(raw: str, current_note_id: Optional[str] = None) -> Tuple[
|
||||
Trennt einen Obsidian-Link [[Target#Section]] in seine Bestandteile Target und Section.
|
||||
Behandelt Self-Links (z.B. [[#Ziele]]), indem die aktuelle note_id eingesetzt wird.
|
||||
|
||||
WP-26 v1.1: Extrahiert Block-ID aus Section-Strings.
|
||||
- Wenn Section "^block-id" enthält, wird nur der Block-ID-Teil extrahiert
|
||||
- Beispiel: "📖 Diagnose: Glioblastom ^kontext" -> section = "kontext"
|
||||
- Beispiel: "^learning" -> section = "learning"
|
||||
- Beispiel: " ^sit" (nur Block-ID) -> section = "sit"
|
||||
|
||||
Returns:
|
||||
Tuple (target_id, target_section)
|
||||
"""
|
||||
@@ -141,6 +147,16 @@ def parse_link_target(raw: str, current_note_id: Optional[str] = None) -> Tuple[
|
||||
target = parts[0].strip()
|
||||
section = parts[1].strip() if len(parts) > 1 else None
|
||||
|
||||
# WP-26 v1.1: Block-ID-Extraktion aus Section
|
||||
# Wenn die Section ein "^" enthält, extrahiere nur den Block-ID-Teil
|
||||
if section and "^" in section:
|
||||
# Finde den ^block-id Teil
|
||||
import re
|
||||
block_id_match = re.search(r'\^([a-zA-Z0-9_-]+)', section)
|
||||
if block_id_match:
|
||||
# Ersetze die gesamte Section durch nur die Block-ID
|
||||
section = block_id_match.group(1)
|
||||
|
||||
# Spezialfall: Self-Link innerhalb derselben Datei
|
||||
if not target and section and current_note_id:
|
||||
target = current_note_id
|
||||
|
||||
Reference in new issue
Block a user