Batch Update Memories - Mem0

Documentation Index

Fetch the complete documentation index at: /llms.txt

Use this file to discover all available pages before exploring further.

Python

# To use the Python SDK, install the package:
# pip install mem0ai

from mem0 import MemoryClient
client = MemoryClient(api_key="your_api_key")

update_memories = [
    {
        "memory_id": "285ed74b-6e05-4043-b16b-3abd5b533496",
        "text": "Watches football"
    },
    {
        "memory_id": "2c9bd859-d1b7-4d33-a6b8-94e0147c4f07",
        "text": "Likes to travel"
    }
]

response = client.batch_update(update_memories)
print(response)

JavaScript

// To use the JavaScript SDK, install the package:
// npm i mem0ai

import MemoryClient from 'mem0ai';
const client = new MemoryClient({ apiKey: "your-api-key" });

const updateMemories = [
    {
        memoryId: "285ed74b-6e05-4043-b16b-3abd5b533496",
        text: "Watches football"
    },
    {
        memoryId: "2c9bd859-d1b7-4d33-a6b8-94e0147c4f07",
        text: "Likes to travel"
    }
];

client.batchUpdate(updateMemories)
    .then(response => console.log('Batch update response:', response))
    .catch(error => console.error(error));

cURL

curl -X PUT "https://api.mem0.ai/v1/batch/" \
     -H "Authorization: Token your-api-key" \
     -H "Content-Type: application/json" \
     -d '{
         "memories": [
             {
                 "memory_id": "285ed74b-6e05-4043-b16b-3abd5b533496",
                 "text": "Watches football"
             },
             {
                 "memory_id": "2c9bd859-d1b7-4d33-a6b8-94e0147c4f07",
                 "text": "Likes to travel"
             }
         ]
     }'

PHP

<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.mem0.ai/v1/batch/",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "PUT",
  CURLOPT_POSTFIELDS => json_encode([
    'memories' => [
        [
                'memory_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
                'text' => '<string>',
                'metadata' => [

]
        ]
    ]
  ]),
  CURLOPT_HTTPHEADER => [
    "Authorization: <api-key>",
    "Content-Type: application/json"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
?>

Go

package main

import (
    "fmt"
    "strings"
    "net/http"
    "io"
)

func main() {

url := "https://api.mem0.ai/v1/batch/"

payload := strings.NewReader("{\n  \"memories\": [\n    {\n      \"memory_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n      \"text\": \"<string>\",\n      \"metadata\": {}\n    }\n  ]\n}")

req, _ := http.NewRequest("PUT", url, payload)

req.Header.Add("Authorization", "<api-key>")
    req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
    body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))
}

Java

HttpResponse<String> response = Unirest.put("https://api.mem0.ai/v1/batch/")
  .header("Authorization", "<api-key>")
  .header("Content-Type", "application/json")
  .body("{\n  \"memories\": [\n    {\n      \"memory_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n      \"text\": \"<string>\",\n      \"metadata\": {}\n    }\n  ]\n}")
  .asString();

Ruby

require 'uri'
require 'net/http'

url = URI("https://api.mem0.ai/v1/batch/")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Put.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"memories\": [\n    {\n      \"memory_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n      \"text\": \"<string>\",\n      \"metadata\": {}\n    }\n  ]\n}"

response = http.request(request)
puts response.read_body

Response Examples

200

{
  "message": "Successfully updated 2 memories"
}

400

{
  "error": "Maximum of 1000 memories can be updated in a single request"
}