TigerGraph as LLM memory stage-1#41
Conversation
Replace SQLite chat-history service with direct TigerGraph storage. - Add TigerGraph memory schema: conversation and message vertices with has_message edge - Add tg_memory.py module for all conversation/message CRUD operations - Auto-install memory schema and GSQL queries on graphrag startup - Add REST endpoints for conversation/message list, create, and delete - Enforce conversation ownership security to isolate users on same graph - Fix agent routing to prioritize last 4 chat history messages for history queries - Add delete button per conversation in sidebar and per message in chat window - Immediate UI feedback on delete without requiring page refresh - Conversation created on first user message (not on New Chat click) Co-authored-by: Cursor <cursoragent@cursor.com>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
| def delete_message_vertices( | ||
| conn: TigerGraphConnection, | ||
| graphname: str, | ||
| message_ids: list[str], | ||
| ) -> int: | ||
| """Permanently delete message vertices by primary id. Returns count deleted.""" | ||
| if not message_ids or not tg_memory_enabled(graphname): | ||
| return 0 | ||
| init_memory_schema(conn, graphname) | ||
| ids = [str(m) for m in message_ids if m] | ||
| if not ids: | ||
| return 0 | ||
| try: | ||
| conn.delVerticesById("message", ids, permanent=True) | ||
| return len(ids) |
There was a problem hiding this comment.
Suggestion: Returning len(ids) assumes every requested vertex existed and was deleted, which can turn missing IDs into false successful deletions. Query the existing vertices first and return the actual deleted count so callers can correctly emit 404 for nonexistent messages. [possible issue, importance: 7]
| def delete_message_vertices( | |
| conn: TigerGraphConnection, | |
| graphname: str, | |
| message_ids: list[str], | |
| ) -> int: | |
| """Permanently delete message vertices by primary id. Returns count deleted.""" | |
| if not message_ids or not tg_memory_enabled(graphname): | |
| return 0 | |
| init_memory_schema(conn, graphname) | |
| ids = [str(m) for m in message_ids if m] | |
| if not ids: | |
| return 0 | |
| try: | |
| conn.delVerticesById("message", ids, permanent=True) | |
| return len(ids) | |
| def delete_message_vertices( | |
| conn: TigerGraphConnection, | |
| graphname: str, | |
| message_ids: list[str], | |
| ) -> int: | |
| """Permanently delete message vertices by primary id. Returns count deleted.""" | |
| if not message_ids or not tg_memory_enabled(graphname): | |
| return 0 | |
| init_memory_schema(conn, graphname) | |
| ids = [str(m) for m in message_ids if m] | |
| if not ids: | |
| return 0 | |
| try: | |
| existing = conn.getVerticesById("message", ids) | |
| existing_ids = [str(v.get("v_id") or v.get("message_id") or v.get("primary_id")) for v in (existing or [])] | |
| existing_ids = [mid for mid in existing_ids if mid] | |
| if not existing_ids: | |
| return 0 | |
| conn.delVerticesById("message", existing_ids, permanent=True) | |
| return len(existing_ids) |
User description
User description
Stage 1: TigerGraph as LLM Chat Memory
Replaces the SQLite-based chat-history Docker service with native TigerGraph storage for all chat conversation data. Each user's conversations and messages are stored as graph vertices (conversation, message) with a has_message edge, enabling per-user isolation, ownership security, and history-aware LLM responses.
PR Type
Enhancement, Security
Description
Add TigerGraph memory schema (conversation, message vertices + has_message edge)
Add tg_memory.py module for all conversation/message CRUD and ownership verification
Auto-install memory schema and GSQL queries on graphrag startup
Remove chat-history SQLite container; update docker-compose.yml to use TigerGraph directly
Add REST endpoints for listing, creating, and deleting conversations and messages
Enforce per-user conversation ownership to isolate users working on the same graph
Fix agent routing to prioritize last 4 chat history messages before falling back to knowledge base
Create conversation on first user message (not on "New Chat" button click)
Add delete button per conversation in sidebar and per message turn in chat window
Immediate UI feedback on delete — no page refresh required
flowchart LR
UI["Chat UI"] -- "send query" --> API["ui.py chat/query endpoints"]
API -- "verify owner + load history" --> MEM["TigerGraph Memory"]
API -- "run agent" --> AGENT["Agent Routing and Execution"]
AGENT -- "history question" --> HIST["History Lookup"]
HIST -- "last 4 exchanges" --> API
API -- "write exchange" --> MEM
UI -- "delete message or conversation" --> API
PR Type
Enhancement, Bug fix
Description
Replace chat-history with TigerGraph memory
Add memory schema startup installation
Secure conversation ownership and deletion
Improve history routing and UI updates
Diagram Walkthrough
File Walkthrough
2 files
Add default startup memory schema flagRemove chat-history and add TigerGraph service14 files
Strengthen prompt guidance for history routingImplement TigerGraph chat memory CRUD layerInstall memory schema during app startupMigrate UI chat APIs to TigerGraphInitialize memory schema with SupportAI setupRemove deleted messages from local chat stateAdd per-message delete confirmation workflowAdd delete action to message controlsAdd conversation delete controls in sidebarAdd query for recent memory exchangesAdd query to list user conversationsAdd query to load conversation messagesAdd query for memory message retrievalDefine conversation message memory graph schema1 files
Add memory package initializer1 files
Fast-path history questions before LLM routing