modified: app/services/semantic_analyzer.py
This commit is contained in:
parent
3629bc3fb9
commit
49cdc9a13f
|
|
@ -1,7 +1,6 @@
|
||||||
"""
|
"""
|
||||||
app/services/semantic_analyzer.py
|
app/services/semantic_analyzer.py
|
||||||
Kapselt die LLM-Strategie für Chunking und Kanten-Extraktion.
|
Kapselt die LLM-Strategie für Chunking und Kanten-Extraktion.
|
||||||
Nutzt die Matrix-Logik aus DiscoveryService für konsistente Kanten-Typen.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
@ -59,14 +58,17 @@ class SemanticAnalyzer:
|
||||||
clean_json = response_json.replace("```json", "").replace("```", "").strip()
|
clean_json = response_json.replace("```json", "").replace("```", "").strip()
|
||||||
data = json.loads(clean_json)
|
data = json.loads(clean_json)
|
||||||
|
|
||||||
# 3a. Typsicherheit des äußeren Arrays
|
# FIX: Typsicherheit auf der Wurzel
|
||||||
if not isinstance(data, list):
|
if isinstance(data, dict):
|
||||||
logger.error("SemanticAnalyzer: JSON root ist kein Array. Fehlerhafte LLM-Antwort.")
|
# LLM hat ein Einzelobjekt geliefert -> wandle es in ein Array
|
||||||
raise ValueError("Root element is not a list.")
|
data = [data]
|
||||||
|
elif not isinstance(data, list):
|
||||||
|
logger.error("SemanticAnalyzer: JSON root ist weder Array noch Objekt. Fehlerhafte LLM-Antwort.")
|
||||||
|
raise ValueError("Root element is not a list or dictionary.")
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
for item in data:
|
for item in data:
|
||||||
# FIX: Typsicherheit auf Item-Ebene
|
# Typsicherheit auf Item-Ebene
|
||||||
if not isinstance(item, dict):
|
if not isinstance(item, dict):
|
||||||
logger.warning(f"SemanticAnalyzer: Ungültiges Chunk-Element ignoriert: {item}")
|
logger.warning(f"SemanticAnalyzer: Ungültiges Chunk-Element ignoriert: {item}")
|
||||||
continue
|
continue
|
||||||
|
|
@ -109,7 +111,6 @@ class SemanticAnalyzer:
|
||||||
logger.error("SemanticAnalyzer: LLM lieferte KEIN valides JSON. Fallback auf Raw Text.")
|
logger.error("SemanticAnalyzer: LLM lieferte KEIN valides JSON. Fallback auf Raw Text.")
|
||||||
return [SemanticChunkResult(content=text, suggested_edges=[])]
|
return [SemanticChunkResult(content=text, suggested_edges=[])]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Wichtig: Wir fangen alle anderen Fehler, um den Prozess nicht abzubrechen.
|
|
||||||
logger.error(f"SemanticAnalyzer Unbehandelter Fehler: {e}")
|
logger.error(f"SemanticAnalyzer Unbehandelter Fehler: {e}")
|
||||||
return [SemanticChunkResult(content=text, suggested_edges=[])]
|
return [SemanticChunkResult(content=text, suggested_edges=[])]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user