Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

fix(explorer): resolve qodo review blocking calls and import schema

ZohaibHassan16dcf26dfa99f5
diff --git a/semantica/explorer/routes/enrich.py b/semantica/explorer/routes/enrich.py
index 606130fe..86eb2892 100644
--- a/semantica/explorer/routes/enrich.py
+++ b/semantica/explorer/routes/enrich.py
@@ -66,8 +66,8 @@ async def predict_links(
raise KeyError(body.node_id)
# Build graph dict
- nodes, _ = session.get_nodes(skip=0, limit=999_999)
- edges, _ = session.get_edges(skip=0, limit=999_999)
+ nodes, _ = await asyncio.to_thread(session.get_nodes, skip=0, limit=999_999)
+ edges, _ = await asyncio.to_thread(session.get_edges, skip=0, limit=999_999)
graph_dict = {
"entities": [{"id": n.get("id"), "type": n.get("type", "entity")} for n in nodes],
"relationships": [
@@ -100,7 +100,7 @@ async def detect_duplicates(
from ...deduplication import DuplicateDetector
detector = DuplicateDetector()
- nodes, _ = session.get_nodes(skip=0, limit=999_999)
+ nodes, _ = await asyncio.to_thread(session.get_nodes, skip=0, limit=999_999)
entities = [
{"id": n.get("id"), "text": n.get("content", n.get("id", "")),
diff --git a/semantica/explorer/routes/export_import.py b/semantica/explorer/routes/export_import.py
index 608db5ff..c326515d 100644
--- a/semantica/explorer/routes/export_import.py
+++ b/semantica/explorer/routes/export_import.py
@@ -151,11 +151,46 @@ async def import_file(
try:
if filename.endswith(".json") or filename.endswith(".jsonld"):
data = json.loads(content)
- nodes = data.get("nodes", data.get("entities", []))
- edges = data.get("edges", data.get("relationships", []))
- added_nodes = await asyncio.to_thread(session.graph.add_nodes, nodes)
- added_edges = await asyncio.to_thread(session.graph.add_edges, edges)
+
+ raw_nodes = data.get("nodes", data.get("entities", []))
+ raw_edges = data.get("edges", data.get("relationships", []))
+
+
+ # KG export uses {id, type, text, metadata}
+ # ContextGraph.add_nodes expects {id, type, properties: {content, ...}}
+ nodes = []
+ for n in raw_nodes:
+ if "properties" in n:
+ nodes.append(n)
+ else:
+ nodes.append({
+ "id": n.get("id"),
+ "type": n.get("type", "entity"),
+ "properties": {
+ "content": n.get("text", n.get("content", n.get("id", ""))),
+ **(n.get("metadata") or {}),
+ },
+ })
+
+ # KG export uses {source, target, type, metadata}
+ # ContextGraph.add_edges expects {source_id, target_id, type, weight, properties}
+ edges = []
+ for r in raw_edges:
+ src = r.get("source_id", r.get("source"))
+ tgt = r.get("target_id", r.get("target"))
+ if not src or not tgt:
+ continue
+ edges.append({
+ "source_id": src,
+ "target_id": tgt,
+ "type": r.get("type", "related_to"),
+ "weight": r.get("weight", 1.0),
+ "properties": r.get("metadata") or r.get("properties") or {},
+ })
+
+ added_nodes = await asyncio.to_thread(session.add_nodes, nodes)
+ added_edges = await asyncio.to_thread(session.add_edges, edges)
result = {
"status": "success",
diff --git a/semantica/explorer/session.py b/semantica/explorer/session.py
index 5c61984b..4ca15333 100644
--- a/semantica/explorer/session.py
+++ b/semantica/explorer/session.py
@@ -215,3 +215,13 @@ class GraphSession:
"""Delete an annotation. Returns True if found and deleted."""
with self._lock:
return self.annotations.pop(annotation_id, None) is not None
+
+ def add_nodes(self, nodes: List[Dict[str, Any]]) -> int:
+ """Thread-safe node addition."""
+ with self._lock:
+ return self.graph.add_nodes(nodes)
+
+ def add_edges(self, edges: List[Dict[str, Any]]) -> int:
+ """Thread-safe edge addition."""
+ with self._lock:
+ return self.graph.add_edges(edges)