Update graph_db_adapter.py, graph_derive_edges.py, graph_subgraph.py, graph_utils.py, ingestion_processor.py, and retriever.py to version 4.1.0: Introduce Scope-Awareness and Section-Filtering features, enhancing edge retrieval and processing. Implement Note-Scope Zones extraction from Markdown, improve edge ID generation with target_section, and prioritize Note-Scope Links during de-duplication. Update documentation for clarity and consistency across modules.

This commit is contained in:
Lars committed 2026-01-10 19:55:51 +01:00
1 parent be2bed9927
commit 39fd15b565
14 files changed
+1004 -37

No files matched your search

+35 -5
View File
@@ -1,9 +1,11 @@
"""
FILE: app/core/graph/graph_db_adapter.py
DESCRIPTION: Datenbeschaffung aus Qdrant für den Graphen.
AUDIT v1.1.1: Volle Unterstützung für WP-15c Metadaten.
Stellt sicher, dass 'target_section' und 'provenance' für die
Super-Edge-Aggregation im Retriever geladen werden.
AUDIT v1.2.0: Gold-Standard v4.1.0 - Scope-Awareness & Section-Filtering.
- Erweiterte Suche nach chunk_id-Edges für Scope-Awareness
- Optionales target_section-Filtering für präzise Section-Links
- Vollständige Metadaten-Unterstützung (provenance, confidence, virtual)
VERSION: 1.2.0 (WP-24c: Gold-Standard v4.1.0)
"""
from typing import List, Dict, Optional
from qdrant_client import QdrantClient
@@ -17,11 +19,22 @@ def fetch_edges_from_qdrant(
prefix: str,
seeds: List[str],
edge_types: Optional[List[str]] = None,
target_section: Optional[str] = None,
chunk_ids: Optional[List[str]] = None,
limit: int = 2048,
) -> List[Dict]:
"""
Holt Edges aus der Datenbank basierend auf Seed-IDs.
WP-15c: Erhält alle Metadaten für das Note-Level Diversity Pooling.
WP-24c v4.1.0: Scope-Aware Edge Retrieval mit Section-Filtering.
Args:
client: Qdrant Client
prefix: Collection-Präfix
seeds: Liste von Note-IDs für die Suche
edge_types: Optionale Filterung nach Kanten-Typen
target_section: Optionales Section-Filtering (für präzise Section-Links)
chunk_ids: Optionale Liste von Chunk-IDs für Scope-Awareness (Chunk-Level Edges)
limit: Maximale Anzahl zurückgegebener Edges
"""
if not seeds or limit <= 0:
return []
@@ -30,13 +43,21 @@ def fetch_edges_from_qdrant(
# Rückgabe: (notes_col, chunks_col, edges_col)
_, _, edges_col = collection_names(prefix)
# Wir suchen Kanten, bei denen die Seed-IDs entweder Quelle, Ziel oder Kontext-Note sind.
# WP-24c v4.1.0: Scope-Awareness - Suche nach Note- UND Chunk-Level Edges
seed_conditions = []
for field in ("source_id", "target_id", "note_id"):
for s in seeds:
seed_conditions.append(
rest.FieldCondition(key=field, match=rest.MatchValue(value=str(s)))
)
# Chunk-Level Edges: Wenn chunk_ids angegeben, suche auch nach chunk_id als source_id
if chunk_ids:
for cid in chunk_ids:
seed_conditions.append(
rest.FieldCondition(key="source_id", match=rest.MatchValue(value=str(cid)))
)
seeds_filter = rest.Filter(should=seed_conditions) if seed_conditions else None
# Optionaler Filter auf spezifische Kanten-Typen (z.B. für Intent-Routing)
@@ -48,11 +69,20 @@ def fetch_edges_from_qdrant(
]
type_filter = rest.Filter(should=type_conds)
# WP-24c v4.1.0: Section-Filtering für präzise Section-Links
section_filter = None
if target_section:
section_filter = rest.Filter(must=[
rest.FieldCondition(key="target_section", match=rest.MatchValue(value=str(target_section)))
])
must = []
if seeds_filter:
must.append(seeds_filter)
if type_filter:
must.append(type_filter)
if section_filter:
must.append(section_filter)
flt = rest.Filter(must=must) if must else None