Skip to content

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_id scoping it to a tenant boundary
  • An importance score (0.0–1.0), defaulting to 0.5
  • A status of active
  • created_at and updated_at timestamps

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
  • pinned memories 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_archived is set to true in 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:

Terminal window
# Soft delete (default) - status set to "deleted", record retained
curl -X DELETE "http://localhost:61001/v1/memories/mem_abc123" \
-H "Authorization: Bearer YOUR_API_KEY"
# Hard delete - record removed from database permanently
curl -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:

Terminal window
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:

Terminal window
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:

Terminal window
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.

Terminal window
# List all workspaces to find the user's workspace
curl "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", ...}
]
}

Before deletion, export the user’s data for your compliance records:

Terminal window
curl "http://localhost:61001/v1/workspaces/ws_user_alice/export" \
-H "Authorization: Bearer YOUR_API_KEY" \
> alice_data_export.ndjson

See 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:

Terminal window
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:

Terminal window
curl "http://localhost:61001/v1/workspaces/ws_user_alice" \
-H "Authorization: Bearer YOUR_API_KEY"
# Expected: 404 Not Found

Partial 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:

Terminal window
# 1. Find all memories about a subject
curl -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 ID
curl -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:

DataWhere it livesHow to find it
User-scoped memories (preferences and directives stored with scope: "user")The _global_user workspace, partitioned by user_idRecall 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 workspacesGET /v1/threads/user/{user_id}
Entities built from the user’s memoriesEach workspace’s entity registryRemoved 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

Terminal window
curl "http://localhost:61001/v1/workspaces/ws_yourworkspaceid/export" \
-H "Authorization: Bearer YOUR_API_KEY" \
> workspace_export.ndjson

Export Parameters

ParameterTypeDefaultDescription
offsetinteger0Skip first N memories
limitinteger0Export at most N memories (0 = all)
include_associationsbooleantrueInclude memory relationship graph
Terminal window
# Export first 500 memories only, without associations
curl "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 counts
  • memory — A single memory record with all fields
  • association — A directed relationship between two memories
  • footer — Final counts summary

Re-importing Exported Data

Exported NDJSON can be imported into any workspace:

Terminal window
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.ndjson

Duplicate 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-thread idle_action (hide or delete) applied. Hidden threads are purged after MEMORYLAYER_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:

Terminal window
# 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:

Terminal window
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 TypeSuggested Retention Strategy
EpisodicDecay monthly; hard-delete below importance 0.1
Semantic / ProceduralPin 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 with include_global: false.
  • _global_user: the requesting user’s own user-scoped memories, always filtered by that user_id. Excluded with include_global_user: false.

How Isolation Works

  • Storage layer: Each workspace’s memories, sessions, and associations are filtered by workspace_id at the SQL level. Queries from workspace A cannot access workspace B’s data.
  • API layer: Workspace is resolved from the session (X-Session-ID header), the request body (workspace_id field), 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.
Use CaseWorkspace Strategy
SaaS with end usersOne workspace per user account
Multi-project agentOne workspace per project or repository
Environment isolationSeparate workspaces for dev, staging, prod
Team / departmentOne workspace per team

Verifying Isolation

Terminal window
# Memories stored in workspace A are not visible from workspace B
curl -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.