Memory Layer
API/Memories

Update memory

Update an existing memory by its ID.

Request

PATCH /v1/memories/{id}

Path Parameters

ParameterTypeRequiredDescription
idstringYesThe unique identifier of the memory to update

Request Body

All fields are optional. Only include the fields you want to update.

FieldTypeDescription
contentstringThe text content of the memory
layerIdstringLayer identifier for organizing memories
metadataobjectAdditional metadata

Example Request

curl -X PATCH "https://api.memorylayer.dev/v1/memories/:memory_id" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "I prefer dark mode in all my applications",
    "metadata": {
      "source": "preferences",
      "category": "ui",
      "updated_reason": "clarification"
    }
  }'

Response

Success Response (200)

{
  "success": true,
  "data": {
    "id": "REPLACE_THIS_MEMORY_ID",
    "layerId": "REPLACE_THIS_LAYER_ID",
    "content": "I prefer dark mode in all my applications",
    "metadata": {
      "source": "preferences",
      "category": "ui",
      "updated_reason": "clarification"
    },
    "embedding": [0.123, -0.456, ...],
    "createdAt": "2024-01-15T10:30:00Z",
    "updatedAt": "2024-01-15T12:45:00Z"
  },
  "message": "Memory updated successfully"
}

Error Responses

Bad Request (400)

{
  "success": false,
  "message": "Invalid request data: content must be a string"
}

Not Found (404)

{
  "success": false,
  "message": "Memory not found"
}

Server Error (500)

{
  "success": false,
  "message": "Failed to update memory"
}

Important Notes

  • Partial Updates: Only the fields you include in the request body will be updated
  • Metadata Replacement: The entire metadata object is replaced, not merged
  • Automatic Timestamps: The updatedAt field is automatically set to the current time
  • Embedding Preservation: The existing embedding is preserved and not regenerated
  • Content Analysis: Content analysis is not re-run on updates

Examples

Update Content Only

curl -X PATCH "https://api.memorylayer.dev/v1/memories/:memory_id" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "Updated content for this memory"
  }'

Update Layer ID

curl -X PATCH "https://api.memorylayer.dev/v1/memories/:memory_id" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "layerId": "REPLACE_THIS_LAYER_ID"
  }'

Update Metadata Only

curl -X PATCH "https://api.memorylayer.dev/v1/memories/:memory_id" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "metadata": {
      "tags": ["important", "personal"],
      "priority": "high",
      "notes": "Updated metadata"
    }
  }'

JavaScript Example

const updates = {
  content: "Updated memory content",
  metadata: {
    tags: ["updated", "important"],
    last_modified_by: "user"
  }
};

const response = await fetch('https://api.memorylayer.dev/v1/memories/:memory_id', {
  method: 'PATCH',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(updates)
});

const result = await response.json();
if (result.success) {
  console.log('Memory updated:', result.data);
} else {
  console.error('Error:', result.message);
}

Python Example

import requests

memory_id = "REPLACE_THIS_MEMORY_ID"
updates = {
    "content": "Updated content",
    "metadata": {
        "category": "work",
        "priority": "high"
    }
}

response = requests.patch(
    f"https://api.memorylayer.dev/v1/memories/{memory_id}",
    headers={
        "Authorization": "Bearer YOUR_API_KEY",
        "Content-Type": "application/json"
    },
    json=updates
)

if response.status_code == 200:
    updated_memory = response.json()["data"]
    print(f"Updated memory: {updated_memory['id']}")
else:
    print(f"Error: {response.json()['message']}")