Build second brain graph 2.0 view

This commit is contained in:
2026-06-05 09:43:24 +02:00
parent 5ebb87db41
commit 89dd603629
3 changed files with 161 additions and 54 deletions

View File

@@ -630,10 +630,14 @@ def _graph_payload_from_rows(rows: list[sqlite3.Row], link_rows: list[sqlite3.Ro
content = (r["content"] or "").strip()
source = str(meta.get("source", "unknown") or "unknown")
tags = [t for t in _safe_json_extract_tags(r["metadata_json"]) if t.strip()]
primary_cluster = tags[0] if tags else source
add_node(eid, "engram", label=(content[:54] or eid[:8]), weight=float(meta.get("access_count", 0) or 0))
nodes[eid].update(
{
"source": source,
"cluster": primary_cluster,
"tags": tags[:8],
"confidence": float(meta.get("confidence", 0.0) or 0.0),
"created": meta.get("created", r["created_at"]),
"modified": meta.get("modified", r["modified_at"]),
@@ -646,17 +650,20 @@ def _graph_payload_from_rows(rows: list[sqlite3.Row], link_rows: list[sqlite3.Ro
sid = f"source:{source}"
add_node(sid, "source", label=source, weight=5)
nodes[sid]["cluster"] = source
add_edge(eid, sid, "from_source", 0.45)
for t in _safe_json_extract_tags(r["metadata_json"]):
for t in tags:
tid = f"tag:{t}"
add_node(tid, "tag", label=t, weight=2)
nodes[tid]["cluster"] = t
add_edge(eid, tid, "has_tag", 0.35)
host = _host_from_meta(r["metadata_json"])
if host:
hid = f"host:{host}"
add_node(hid, "host", label=host, weight=3)
nodes[hid]["cluster"] = source
add_edge(eid, hid, "grounded_at", 0.25)
for lr in link_rows: