Data Management & GDPR Compliance
This guide covers how memory data flows through MemoryLayer, how to delete or export it, and how to fulfill GDPR Article 17 (right to erasure) requests using the existing API.
Data Lifecycle
Memory data passes through three phases:
1. Creation
Memories are created explicitly via POST /v1/memories, or implicitly when a session is committed (POST /v1/sessions/{session_id}/commit). At creation, each memory receives:
- A unique
id(e.g.mem_a1b2c3d4e5f6g7h8) - A
workspace_idscoping it to a tenant boundary - An
importancescore (0.0–1.0), defaulting to0.5 - A
statusofactive created_atandupdated_attimestamps
2. Access and Decay
Memories are retrieved through POST /v1/memories/recall (hybrid vector + keyword search; see Recall & Retrieval) or POST /v1/memories/reflect (LLM synthesis). Between retrievals, importance naturally decays:
- Episodic memories (events, interactions) decay over time
- Semantic memories (facts, preferences) and procedural memories are long-lived
pinnedmemories are exempt from decay- Decay is applied explicitly via
POST /v1/memories/{memory_id}/decay
3. Deletion
Memories can be soft-deleted (default) or hard-deleted (permanent). See Deletion below.
Deletion
Soft Delete vs Hard Delete
By default, DELETE /v1/memories/{memory_id} performs a soft delete: the memory’s status is set to deleted and deleted_at is recorded. Soft-deleted memories:
- Are excluded from recall and reflect results
- Remain in the database and can be restored
- Are not returned when
include_archivedis set totruein recall requests
The versioned endpoints POST /v1/memories/{memory_id}/delete and POST /v1/memories/{memory_id}/restore soft-delete and restore a memory under optimistic concurrency. Both require an If-Match header carrying the memory’s current ETag, which GET /v1/memories/{memory_id} returns.
To permanently remove a memory from storage, pass the hard=true query parameter:
# Soft delete (default) - status set to "deleted", record retainedcurl -X DELETE "http://localhost:61001/v1/memories/mem_abc123" \ -H "Authorization: Bearer YOUR_API_KEY"
# Hard delete - record removed from database permanentlycurl -X DELETE "http://localhost:61001/v1/memories/mem_abc123?hard=true" \ -H "Authorization: Bearer YOUR_API_KEY"Both return 204 No Content on success.
Batch Deletion
To delete multiple memories in a single request, use the batch endpoint. Each delete operation in the batch also supports the hard flag:
curl -X POST "http://localhost:61001/v1/memories/batch" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "operations": [ {"op": "delete", "memory_id": "mem_abc123", "hard": true}, {"op": "delete", "memory_id": "mem_def456", "hard": true}, {"op": "delete", "memory_id": "mem_ghi789", "hard": false} ] }'Response:
{ "total_operations": 3, "successful": 3, "failed": 0, "results": [ {"index": 0, "type": "delete", "status": "success", "memory_id": "mem_abc123"}, {"index": 1, "type": "delete", "status": "success", "memory_id": "mem_def456"}, {"index": 2, "type": "delete", "status": "success", "memory_id": "mem_ghi789"} ]}Purging an Entire Workspace
To delete a workspace and all its associated data (memories, sessions, associations), use:
curl -X DELETE "http://localhost:61001/v1/workspaces/ws_yourworkspaceid" \ -H "Authorization: Bearer YOUR_API_KEY"Returns 204 No Content on success. This is the most complete data removal operation available. In one transaction, it removes the workspace record and every workspace-scoped row: memories, associations, contradictions, sessions and working memory, documents and pages, entities, chat threads, skills, and so on. It does not touch data stored outside the workspace; see User-Scoped Data.
Deleting a Session
To delete a session and its working memory context:
curl -X DELETE "http://localhost:61001/v1/sessions/sess_yoursessionid" \ -H "Authorization: Bearer YOUR_API_KEY"Session deletion removes the session and its working memory entries. Long-term memories previously committed from this session remain in the workspace and must be deleted separately if required.
Right to Erasure (GDPR Article 17)
GDPR Article 17 grants data subjects the right to request erasure of their personal data. This section provides a step-by-step procedure to fulfill such a request using the MemoryLayer API.
Step 1: Identify the User’s Workspace
If each user has a dedicated workspace, the workspace ID is the primary handle for their data.
# List all workspaces to find the user's workspacecurl "http://localhost:61001/v1/workspaces" \ -H "Authorization: Bearer YOUR_API_KEY"{ "workspaces": [ {"id": "ws_user_alice", "name": "Alice's Workspace", ...}, {"id": "ws_user_bob", "name": "Bob's Workspace", ...} ]}Step 2: Export Data for Audit (Optional but Recommended)
Before deletion, export the user’s data for your compliance records:
curl "http://localhost:61001/v1/workspaces/ws_user_alice/export" \ -H "Authorization: Bearer YOUR_API_KEY" \ > alice_data_export.ndjsonSee Data Export for full details on the export format.
Step 3: Delete the Workspace
A single workspace deletion removes all memories, sessions, working memory, and associations for that user:
curl -X DELETE "http://localhost:61001/v1/workspaces/ws_user_alice" \ -H "Authorization: Bearer YOUR_API_KEY"204 No Content confirms the workspace and all its workspace-scoped data have been removed. Then remove the user’s user-scoped data, if any.
Step 4: Verify Deletion
Confirm the workspace no longer exists:
curl "http://localhost:61001/v1/workspaces/ws_user_alice" \ -H "Authorization: Bearer YOUR_API_KEY"# Expected: 404 Not FoundPartial Erasure (Selective Memory Deletion)
If a user shares a workspace with other data (not recommended for GDPR use cases), you can recall memories by subject_id and delete them individually:
# 1. Find all memories about a subjectcurl -X POST "http://localhost:61001/v1/memories/recall" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "query": "all information", "workspace_id": "ws_shared", "subject_id": "user_alice", "limit": 100 }'
# 2. Hard-delete each returned memory IDcurl -X DELETE "http://localhost:61001/v1/memories/mem_abc123?hard=true" \ -H "Authorization: Bearer YOUR_API_KEY"User-Scoped Data
Some per-user data is deliberately stored outside project workspaces, so deleting a workspace does not remove it:
| Data | Where it lives | How to find it |
|---|---|---|
User-scoped memories (preferences and directives stored with scope: "user") | The _global_user workspace, partitioned by user_id | Recall with workspace_id: "_global_user" and the user’s user_id, or read POST /v1/representation/user |
User-owned chat threads (ownership: "user", the default) | A per-user thread store that spans workspaces | GET /v1/threads/user/{user_id} |
| Entities built from the user’s memories | Each workspace’s entity registry | Removed with the workspace |
Delete user-scoped memories by ID with DELETE /v1/memories/{id}?hard=true, sending an X-Workspace-ID: _global_user header (or use the batch endpoint the same way), and delete user-owned threads with DELETE /v1/threads/{thread_id}.
Data Export
The workspace export endpoint streams all memories and associations as NDJSON (newline-delimited JSON), suitable for backup, migration, or GDPR data portability responses.
Export a Workspace
curl "http://localhost:61001/v1/workspaces/ws_yourworkspaceid/export" \ -H "Authorization: Bearer YOUR_API_KEY" \ > workspace_export.ndjsonExport Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
offset | integer | 0 | Skip first N memories |
limit | integer | 0 | Export at most N memories (0 = all) |
include_associations | boolean | true | Include memory relationship graph |
# Export first 500 memories only, without associationscurl "http://localhost:61001/v1/workspaces/ws_yourworkspaceid/export?limit=500&include_associations=false" \ -H "Authorization: Bearer YOUR_API_KEY"NDJSON Format
Each line is a JSON object with a type field:
{"type":"header","version":"1.0","workspace_id":"ws_abc","exported_at":"2026-04-02T10:00:00Z","total_memories":42,"total_associations":17,"offset":0,"limit":0}{"type":"memory","index":0,"data":{"id":"mem_abc123","content":"User prefers TypeScript","type":"semantic","importance":0.8,"tags":["language","preference"],"created_at":"2026-01-15T09:30:00Z",...}}{"type":"memory","index":1,"data":{...}}{"type":"association","data":{"source_id":"mem_abc123","target_id":"mem_def456","relationship_type":"similar_to","strength":0.75,"metadata":{}}}{"type":"footer","memories_exported":42,"associations_exported":17}Line types:
header— Export metadata and countsmemory— A single memory record with all fieldsassociation— A directed relationship between two memoriesfooter— Final counts summary
Re-importing Exported Data
Exported NDJSON can be imported into any workspace:
curl -X POST "http://localhost:61001/v1/workspaces/ws_newworkspace/import" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/x-ndjson" \ --data-binary @workspace_export.ndjsonDuplicate detection uses content_hash — memories already present in the target workspace are skipped without error.
Data Retention
MemoryLayer does not automatically delete memories. Memory retention is governed by two mechanisms, importance decay and pinning. Other data has its own time-based limits:
- Chat threads. A thread idle for
MEMORYLAYER_CHAT_THREAD_IDLE_RETENTION_DAYS(default 7) has its per-threadidle_action(hideordelete) applied. Hidden threads are purged afterMEMORYLAYER_CHAT_THREAD_HIDDEN_DELETE_DAYS(default 0, which disables purging). - Context-delta change events are kept for
MEMORYLAYER_CONTEXT_EVENT_RETENTION_DAYS(default 30). - Sessions expire at their TTL. Expired sessions are auto-committed, then deleted.
Importance Decay
Importance is a float from 0.0 (forgotten) to 1.0 (critical). The decay endpoint reduces importance on demand:
# Reduce a memory's importance by 10%curl -X POST "http://localhost:61001/v1/memories/mem_abc123/decay" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"decay_rate": 0.1}'Memories with very low importance scores are candidates for archival or deletion in your retention workflows, but MemoryLayer does not delete them automatically — your application must implement that logic.
Pinning
A pinned memory is exempt from decay and will not appear in archival candidate lists. Pin a memory to mark it as permanently important:
curl -X PUT "http://localhost:61001/v1/memories/mem_abc123" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"pinned": true}'Retention Recommendations
| Memory Type | Suggested Retention Strategy |
|---|---|
| Episodic | Decay monthly; hard-delete below importance 0.1 |
| Semantic / Procedural | Pin critical facts; decay infrequently |
| Working (session) | Expire via session TTL; commit to long-term or discard |
Workspace Isolation
Every memory belongs to exactly one workspace. Recall reads only the requested workspace plus two shared stores, and you can turn both off per request:
_global: tenant-wide shared knowledge. Excluded withinclude_global: false._global_user: the requesting user’s own user-scoped memories, always filtered by thatuser_id. Excluded withinclude_global_user: false.
How Isolation Works
- Storage layer: Each workspace’s memories, sessions, and associations are filtered by
workspace_idat the SQL level. Queries from workspace A cannot access workspace B’s data. - API layer: Workspace is resolved from the session (
X-Session-IDheader), the request body (workspace_idfield), or defaults to_default. An explicit workspace in the request body overrides session context. - Authorization: Operations on a workspace require authorization for that specific
workspace_id.
Recommended Isolation Patterns
| Use Case | Workspace Strategy |
|---|---|
| SaaS with end users | One workspace per user account |
| Multi-project agent | One workspace per project or repository |
| Environment isolation | Separate workspaces for dev, staging, prod |
| Team / department | One workspace per team |
Verifying Isolation
# Memories stored in workspace A are not visible from workspace Bcurl -X POST "http://localhost:61001/v1/memories/recall" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"query": "anything", "workspace_id": "ws_workspace_b", "limit": 10}'# Returns 0 results for data only in ws_workspace_a# (add "include_global": false to also exclude the shared _global workspace)The _default Workspace
When no workspace is specified, memories land in _default. This workspace:
- Is auto-created on first use
- Is shared by every caller that does not name a workspace
- Is suitable for single-user or development deployments
For production multi-user deployments, always specify explicit workspace IDs to maintain isolation and enable clean data deletion per user.