Delete 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")

# Delete all memories for a specific user
client.delete_all(user_id="<user_id>")

# Delete all memories for every user in the project (wildcard)
client.delete_all(user_id="*")

# Full project wipe: all four filters must be explicitly set to "*"
client.delete_all(user_id="*", agent_id="*", app_id="*", run_id="*")

# NOTE: Calling delete_all() with no filters raises a validation error.
# At least one filter is required to prevent accidental data loss.

JavaScript

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

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

// Delete all memories for a specific user
client.deleteAll({ user_id: "<user_id>" })
  .then(result => console.log(result))
  .catch(error => console.error(error));

// Delete all memories for every user in the project (wildcard)
client.deleteAll({ user_id: "*" })
  .then(result => console.log(result))
  .catch(error => console.error(error));

// Full project wipe: all four filters must be explicitly set to "*"
client.deleteAll({ user_id: "*", agent_id: "*", app_id: "*", run_id: "*" })
  .then(result => console.log(result))
  .catch(error => console.error(error));

cURL

# Delete memories for a specific user
curl --request DELETE \
  --url 'https://api.mem0.ai/v1/memories/?user_id=<user_id>' \
  --header 'Authorization: Token <api-key>'

# Delete memories for all users (wildcard)
curl --request DELETE \
  --url 'https://api.mem0.ai/v1/memories/?user_id=*' \
  --header 'Authorization: Token <api-key>'

# Full project wipe: all four filters must be set to *
curl --request DELETE \
  --url 'https://api.mem0.ai/v1/memories/?user_id=*&agent_id=*&app_id=*&run_id=*' \
  --header 'Authorization: Token <api-key>'

Go

package main

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

func main() {

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

req, _ := http.NewRequest("DELETE", url, nil)

req.Header.Add("Authorization", "Token <api-key>")

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

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

fmt.Println(res)
    fmt.Println(string(body))
}

PHP

<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.mem0.ai/v1/memories/",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "DELETE",
  CURLOPT_HTTPHEADER => [
    "Authorization: Token <api-key>"
  ],
]);

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

curl_close($curl);

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

Java

HttpResponse<String> response = Unirest.delete("https://api.mem0.ai/v1/memories/")
  .header("Authorization", "Token <api-key>")
  .asString();

Ruby

require 'uri'
require 'net/http'

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

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

request = Net::HTTP::Delete.new(url)
request["Authorization"] = '<api-key>'

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

Response

204 - application/json

Successful deletion of memories.

{
  "message": "Memories deleted successfully!"
}

Authorizations

Query Parameters

Response

204 - application/json
Successful deletion of memories.

{
  "message": "Memories deleted successfully!"
}