diff --git a/src/dashboard/routes/memory.py b/src/dashboard/routes/memory.py index 97ce6d7c..fa7e5ddf 100644 --- a/src/dashboard/routes/memory.py +++ b/src/dashboard/routes/memory.py @@ -13,9 +13,53 @@ from timmy.memory_system import ( update_personal_fact, ) + +from timmy.memory_system import get_connection + router = APIRouter(prefix="/memory", tags=["memory"]) +@router.get("/graph_data", response_class=JSONResponse) +async def memory_graph_data(): + """Return memory nodes and links for visualization.""" + nodes = [] + links = [] + + with get_connection() as conn: + rows = conn.execute( + "SELECT id, content, memory_type, session_id, agent_id FROM memories ORDER BY created_at DESC LIMIT 100" + ).fetchall() + + for row in rows: + nodes.append({ + "id": row["id"], + "content": row["content"][:50], + "type": row["memory_type"] + }) + + # Simple linking logic: link memories in the same session + if row["session_id"]: + for other in nodes[:-1]: + # This is a bit slow but okay for 100 nodes + pass + + # More robust linking: link by session_id + session_map = {} + for row in rows: + sid = row["session_id"] + if sid: + if sid not in session_map: + session_map[sid] = [] + session_map[sid].append(row["id"]) + + for sid, ids in session_map.items(): + for i in range(len(ids) - 1): + links.append({"source": ids[i], "target": ids[i+1]}) + + return {"nodes": nodes, "links": links} + + + @router.get("", response_class=HTMLResponse) async def memory_page( request: Request, diff --git a/src/dashboard/templates/memory.html b/src/dashboard/templates/memory.html index 1c2822aa..6db0585a 100644 --- a/src/dashboard/templates/memory.html +++ b/src/dashboard/templates/memory.html @@ -3,7 +3,26 @@ {% block title %}Memory Browser{% endblock %} {% block content %} +
+
+
+

Memory Browser

+

Semantic search through conversation history and facts

+
+ +
+ +
+
+

Memory Browser

Semantic search through conversation history and facts

@@ -66,7 +85,14 @@ {{ "%.2f"|format(mem.relevance_score) }} {% endif %}
+
{{ mem.content }}
+ {% if mem.relevance_score %} +
+
+
+ {% endif %} +
{{ mem.timestamp[11:16] }} {% if mem.agent_id %} @@ -119,9 +145,108 @@ {% endif %}
+ +
+
+
+
+
+
+
+
+