Welcome to the Mem0 quickstart guide. This guide will help you get up and running with Mem0 in no time.

Installation

To install Mem0, you can use npm. Run the following command in your terminal:

npm install mem0ai

Basic Usage

Initialize Mem0

import { Memory } from 'mem0ai/oss';

const memory = new Memory();

Store a Memory

const messages = [
    {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"},
    {"role": "assistant", "content": "How about a thriller movies? They can be quite engaging."},
    {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."},
    {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."}
]

await memory.add(messages, { userId: "alice", metadata: { category: "movie_recommendations" } });

Retrieve Memories

// Get all memories
const allMemories = await memory.getAll({ userId: "alice" });
console.log(allMemories)

// Get a single memory by ID
const singleMemory = await memory.get('892db2ae-06d9-49e5-8b3e-585ef9b85b8e');
console.log(singleMemory);

Search Memories

const result = await memory.search('What do you know about me?', { userId: "alice" });
console.log(result);

Update a Memory

const result = await memory.update(
  '892db2ae-06d9-49e5-8b3e-585ef9b85b8e',
  'I love India, it is my favorite country.'
);
console.log(result);

Memory History

const history = await memory.history('892db2ae-06d9-49e5-8b3e-585ef9b85b8e');
console.log(history);

Delete Memory

// Delete a memory by id
await memory.delete('892db2ae-06d9-49e5-8b3e-585ef9b85b8e');

// Delete all memories for a user
await memory.deleteAll({ userId: "alice" });

Reset Memory

await memory.reset(); // Reset all memories

Configuration Parameters

Mem0 offers extensive configuration options to customize its behavior according to your needs. These configurations span across different components like vector stores, language models, embedders, and graph stores.

If you have any questions, please feel free to reach out to us using one of the following methods: