This document is intended for use by an LLM coding assistant to implement a structured memeory layer to Synapse.
Add a structured memory layer alongside the existing PGVector-based memory system.
This layer will:
- Store authoritative, user-curated context (e.g. infrastructure, preferences)
- Be retrieved deterministically (no embeddings)
- Be injected into prompts before LLM responses
This is NOT a replacement for vector memory — it is a complementary system.
Current:
LLM → MCP → API → PGVector (search_memories)
Target:
- Fetch structured memory (PostgreSQL JSONB)
- Fetch vector memory (existing search_memories)
- Combine both
- Return to LLM
Modify:
db/init.sql
Add:
CREATE TABLE IF NOT EXISTS structured_memory (
key TEXT PRIMARY KEY,
value JSONB NOT NULL,
updated_at TIMESTAMP DEFAULT NOW()
);Modify:
api/app/db.py
Add function:
def get_structured_memory(key: str):
query = "SELECT value FROM structured_memory WHERE key = %s"
result = execute_query(query, (key,))
return result[0]["value"] if result else NoneModify:
api/app/main.py
Add endpoint:
@app.get("/structured_memory/{key}")
def fetch_structured_memory(key: str):
value = get_structured_memory(key)
if value is None:
return {"key": key, "value": None}
return {"key": key, "value": value}Modify:
mcp/server.py
{
"name": "get_structured_memory",
"description": "Retrieve structured, authoritative user context",
"parameters": {
"type": "object",
"properties": {
"key": {"type": "string"}
},
"required": ["key"]
}
}elif tool_name == "get_structured_memory":
key = arguments["key"]
response = requests.get(f"{API_URL}/structured_memory/{key}")
return response.json()This is where most of the value comes from.
New flow:
- Call get_structured_memory
- Call search_memories
- Combine both before responding
Format:
## Structured Context (Authoritative)
### Infrastructure
<render JSON as readable text>
### Preferences
<render JSON>
---
## Retrieved Context
<existing vector search results>
---
## User Query
<original query>def render_structured_memory(data: dict) -> str:
return json.dumps(data, indent=2)End of Plan