mem0ai 1.0.39 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -334
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4473 -108
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +157 -92
- package/dist/index.mjs.map +1 -1
- package/dist/module-KU56J2J6.mjs +4313 -0
- package/dist/module-KU56J2J6.mjs.map +1 -0
- package/dist/oss/index.d.mts +348 -0
- package/dist/oss/index.d.ts +348 -0
- package/dist/oss/index.js +1711 -0
- package/dist/oss/index.js.map +1 -0
- package/dist/oss/index.mjs +1664 -0
- package/dist/oss/index.mjs.map +1 -0
- package/package.json +109 -77
package/README.md
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
# Mem0 - The Memory Layer for Your AI Apps
|
|
2
2
|
|
|
3
|
-
Mem0 is a self-improving memory layer for LLM applications, enabling personalized AI experiences that save costs and delight users.
|
|
4
|
-
|
|
5
|
-
Get started with Mem0 Platform in minutes using the Node.js client.
|
|
3
|
+
Mem0 is a self-improving memory layer for LLM applications, enabling personalized AI experiences that save costs and delight users. We offer both cloud and open-source solutions to cater to different needs.
|
|
6
4
|
|
|
7
5
|
## 1. Installation
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
For the open-source version, you can install the Mem0 package using npm:
|
|
10
8
|
|
|
11
9
|
```bash
|
|
12
10
|
npm i mem0ai
|
|
@@ -14,355 +12,45 @@ npm i mem0ai
|
|
|
14
12
|
|
|
15
13
|
## 2. API Key Setup
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
2. Copy your API Key from the dashboard
|
|
19
|
-
|
|
20
|
-
## 3. Instantiate Client
|
|
15
|
+
For the cloud offering, sign in to [Mem0 Platform](https://app.mem0.ai/dashboard/api-keys) to obtain your API Key.
|
|
21
16
|
|
|
22
|
-
|
|
23
|
-
```javascript
|
|
24
|
-
import MemoryClient from 'mem0ai';
|
|
17
|
+
## 3. Client Features
|
|
25
18
|
|
|
26
|
-
|
|
19
|
+
### Cloud Offering
|
|
27
20
|
|
|
28
|
-
|
|
29
|
-
apiKey: apiKey,
|
|
30
|
-
organizationId: 'your-organization-id-here', // Optional
|
|
31
|
-
projectId: 'your-project-id-here' // Optional
|
|
32
|
-
});
|
|
21
|
+
The cloud version provides a comprehensive set of features, including:
|
|
33
22
|
|
|
34
|
-
|
|
23
|
+
- **Memory Operations**: Perform CRUD operations on memories.
|
|
24
|
+
- **Search Capabilities**: Search for relevant memories using advanced filters.
|
|
25
|
+
- **Memory History**: Track changes to memories over time.
|
|
26
|
+
- **Error Handling**: Robust error handling for API-related issues.
|
|
27
|
+
- **Async/Await Support**: All methods return promises for easy integration.
|
|
35
28
|
|
|
36
|
-
|
|
29
|
+
### Open-Source Offering
|
|
37
30
|
|
|
38
|
-
|
|
31
|
+
The open-source version includes the following top features:
|
|
39
32
|
|
|
33
|
+
- **Memory Management**: Add, update, delete, and retrieve memories.
|
|
34
|
+
- **Vector Store Integration**: Supports various vector store providers for efficient memory retrieval.
|
|
35
|
+
- **LLM Support**: Integrates with multiple LLM providers for generating responses.
|
|
36
|
+
- **Customizable Configuration**: Easily configure memory settings and providers.
|
|
37
|
+
- **SQLite Storage**: Use SQLite for memory history management.
|
|
40
38
|
|
|
41
39
|
## 4. Memory Operations
|
|
42
40
|
|
|
43
|
-
Mem0 provides a simple and customizable interface for performing
|
|
44
|
-
|
|
45
|
-
### 4.1 Create Memories
|
|
46
|
-
|
|
47
|
-
You can create long-term and short-term memories for your users, AI Agents, etc. Here are some examples:
|
|
48
|
-
|
|
49
|
-
#### Long-term memory for a user
|
|
50
|
-
|
|
51
|
-
```javascript
|
|
52
|
-
const messages = [
|
|
53
|
-
{ role: "user", content: "Hi, I'm Alex. I'm a vegetarian and I'm allergic to nuts." },
|
|
54
|
-
{ role: "assistant", content: "Hello Alex! I've noted that you're a vegetarian and have a nut allergy. I'll keep this in mind for any food-related recommendations or discussions." }
|
|
55
|
-
];
|
|
56
|
-
|
|
57
|
-
client.add(messages, { user_id: "alex" })
|
|
58
|
-
.then(result => console.log(result))
|
|
59
|
-
.catch(error => console.error(error));
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
#### Short-term memory for a user session
|
|
63
|
-
|
|
64
|
-
```javascript
|
|
65
|
-
const messages = [
|
|
66
|
-
{ role: "user", content: "I'm planning a trip to Japan next month." },
|
|
67
|
-
{ role: "assistant", content: "That's exciting, Alex! A trip to Japan next month sounds wonderful. Would you like some recommendations for vegetarian-friendly restaurants in Japan?" },
|
|
68
|
-
{ role: "user", content: "Yes, please! Especially in Tokyo." },
|
|
69
|
-
{ role: "assistant", content: "Great! I'll remember that you're interested in vegetarian restaurants in Tokyo for your upcoming trip. I'll prepare a list for you in our next interaction." }
|
|
70
|
-
];
|
|
71
|
-
|
|
72
|
-
client.add(messages, { user_id: "alex123", run_id: "trip-planning-2024" })
|
|
73
|
-
.then(result => console.log(result))
|
|
74
|
-
.catch(error => console.error(error));
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
#### Long-term memory for agents
|
|
78
|
-
|
|
79
|
-
```javascript
|
|
80
|
-
const messages = [
|
|
81
|
-
{ role: "system", content: "You are a personalized travel assistant. Remember user preferences and provide tailored recommendations." },
|
|
82
|
-
{ role: "assistant", content: "Understood. I'll maintain personalized travel preferences for each user and provide customized recommendations based on their dietary restrictions, interests, and past interactions." }
|
|
83
|
-
];
|
|
84
|
-
|
|
85
|
-
client.add(messages, { agent_id: "travel-assistant" })
|
|
86
|
-
.then(result => console.log(result))
|
|
87
|
-
.catch(error => console.error(error));
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
#### Infer Memories
|
|
91
|
-
|
|
92
|
-
By default, Mem0 will infer memories based on the content of the messages. You can disable this behavior by passing `infer: false` in the options and directly store the messages.
|
|
93
|
-
|
|
94
|
-
```javascript
|
|
95
|
-
const messages = [
|
|
96
|
-
{ role: "user", content: "Hi, I'm Alex. I'm a vegetarian and I'm allergic to nuts." },
|
|
97
|
-
{ role: "assistant", content: "Hello Alex! I've noted that you're a vegetarian and have a nut allergy. I'll keep this in mind for any food-related recommendations or discussions." }
|
|
98
|
-
];
|
|
99
|
-
|
|
100
|
-
client.add(messages, { user_id: "alex", infer: false })
|
|
101
|
-
.then(result => console.log(result))
|
|
102
|
-
.catch(error => console.error(error));
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### 4.2 Search Relevant Memories
|
|
106
|
-
|
|
107
|
-
You can search for relevant memories using both v1 and v2 of the API:
|
|
108
|
-
|
|
109
|
-
#### V1 Search (Default)
|
|
110
|
-
|
|
111
|
-
```javascript
|
|
112
|
-
const query = "What do you know about me?";
|
|
113
|
-
const options = { user_id: "alex" };
|
|
114
|
-
|
|
115
|
-
client.search(query, options)
|
|
116
|
-
.then(results => console.log(results))
|
|
117
|
-
.catch(error => console.error(error));
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
#### V2 Search
|
|
121
|
-
|
|
122
|
-
```javascript
|
|
123
|
-
const query = "What do you know about me?";
|
|
124
|
-
const options = {
|
|
125
|
-
filters: {
|
|
126
|
-
OR: [
|
|
127
|
-
{ agent_id: "travel-assistant" },
|
|
128
|
-
{ user_id: "alex" }
|
|
129
|
-
]
|
|
130
|
-
},
|
|
131
|
-
threshold: 0.1,
|
|
132
|
-
api_version: 'v2'
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
client.search(query, options)
|
|
136
|
-
.then(results => console.log(results))
|
|
137
|
-
.catch(error => console.error(error));
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
This example demonstrates a more advanced V2 search:
|
|
141
|
-
- It searches for dietary preferences
|
|
142
|
-
- Filters results to only include memories associated with either the "travel-assistant" agent or the user "alex"
|
|
143
|
-
- Sets a similarity threshold of 0.1 to include more potentially relevant results
|
|
144
|
-
|
|
145
|
-
You can adjust the `query`, `filters`, and `threshold` as needed for your specific use case.
|
|
146
|
-
|
|
147
|
-
### 4.3 Get All Memories
|
|
148
|
-
|
|
149
|
-
Fetch all memories for a user, agent, or session using the getAll() method.
|
|
150
|
-
|
|
151
|
-
#### Get all memories of an AI Agent
|
|
152
|
-
|
|
153
|
-
```javascript
|
|
154
|
-
client.getAll({ agent_id: "travel-assistant" })
|
|
155
|
-
.then(memories => console.log(memories))
|
|
156
|
-
.catch(error => console.error(error));
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
#### Get all memories of a user
|
|
160
|
-
|
|
161
|
-
```javascript
|
|
162
|
-
client.getAll({ user_id: "alex" })
|
|
163
|
-
.then(memories => console.log(memories))
|
|
164
|
-
.catch(error => console.error(error));
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
#### Get short-term memories for a session
|
|
168
|
-
|
|
169
|
-
```javascript
|
|
170
|
-
client.getAll({ user_id: "alex123", run_id: "trip-planning-2024" })
|
|
171
|
-
.then(memories => console.log(memories))
|
|
172
|
-
.catch(error => console.error(error));
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
#### Get all memories (V2 endpoint)
|
|
176
|
-
|
|
177
|
-
The v2 endpoint offers more filters and users can search for memories by using custom filters such as `OR`, `AND` etc.
|
|
178
|
-
|
|
179
|
-
```javascript
|
|
180
|
-
const options = {
|
|
181
|
-
filters: {
|
|
182
|
-
OR: [
|
|
183
|
-
{ user_id: "alex" },
|
|
184
|
-
{ agent_id: "shopping-assistant" }
|
|
185
|
-
]
|
|
186
|
-
},
|
|
187
|
-
api_version: 'v2'
|
|
188
|
-
};
|
|
189
|
-
const memories = await client.getAll(options);
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
#### Get specific memory
|
|
194
|
-
|
|
195
|
-
```javascript
|
|
196
|
-
client.get("memory-id-here")
|
|
197
|
-
.then(memory => console.log(memory))
|
|
198
|
-
.catch(error => console.error(error));
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
#### Get all memories with pagination
|
|
202
|
-
|
|
203
|
-
```javascript
|
|
204
|
-
// Get memories with pagination (50 items per page)
|
|
205
|
-
client.getAll({ user_id: "alex", page: 1, page_size: 50 })
|
|
206
|
-
.then(memories => console.log(memories))
|
|
207
|
-
.catch(error => console.error(error));
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
The paginated response includes:
|
|
211
|
-
- `count`: Total number of memories
|
|
212
|
-
- `next`: URL for the next page (null if no more pages)
|
|
213
|
-
- `previous`: URL for the previous page (null if on first page)
|
|
214
|
-
- `results`: Array of memories for the current page
|
|
215
|
-
|
|
216
|
-
### 4.4 Get all users
|
|
217
|
-
|
|
218
|
-
Get all users for which you have memories.
|
|
219
|
-
|
|
220
|
-
```javascript
|
|
221
|
-
client.users()
|
|
222
|
-
.then(users => console.log(users))
|
|
223
|
-
.catch(error => console.error(error));
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
### 4.5 Memory History
|
|
227
|
-
|
|
228
|
-
Get history of how a memory has changed over time:
|
|
229
|
-
|
|
230
|
-
```javascript
|
|
231
|
-
// Add some message to create history
|
|
232
|
-
let messages = [{ role: "user", content: "I recently tried chicken and I loved it. I'm thinking of trying more non-vegetarian dishes.." }];
|
|
233
|
-
client.add(messages, { user_id: "alex" })
|
|
234
|
-
.then(result => {
|
|
235
|
-
// Add second message to update history
|
|
236
|
-
messages.push({ role: 'user', content: 'I turned vegetarian now.' });
|
|
237
|
-
return client.add(messages, { user_id: "alex" });
|
|
238
|
-
})
|
|
239
|
-
.then(result => {
|
|
240
|
-
// Get history of how memory changed over time
|
|
241
|
-
const memoryId = result.id; // Assuming the API returns the memory ID
|
|
242
|
-
return client.history(memoryId);
|
|
243
|
-
})
|
|
244
|
-
.then(history => console.log(history))
|
|
245
|
-
.catch(error => console.error(error));
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
### 4.6 Delete Memory
|
|
249
|
-
|
|
250
|
-
Delete specific memory:
|
|
251
|
-
|
|
252
|
-
```javascript
|
|
253
|
-
client.delete("memory-id-here")
|
|
254
|
-
.then(result => console.log(result))
|
|
255
|
-
.catch(error => console.error(error));
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
Delete all users for which you have memories:
|
|
259
|
-
|
|
260
|
-
```javascript
|
|
261
|
-
client.deleteUsers()
|
|
262
|
-
.then(result => console.log(result))
|
|
263
|
-
.catch(error => console.error(error));
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
Delete all memories of a user:
|
|
267
|
-
|
|
268
|
-
```javascript
|
|
269
|
-
client.deleteAll({ user_id: "alex" })
|
|
270
|
-
.then(result => console.log(result))
|
|
271
|
-
.catch(error => console.error(error));
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
Fun fact: You can also delete the memory using the `add()` method by passing a natural language command:
|
|
275
|
-
|
|
276
|
-
```javascript
|
|
277
|
-
client.add("Delete all of my food preferences", { user_id: "alex" })
|
|
278
|
-
.then(result => console.log(result))
|
|
279
|
-
.catch(error => console.error(error));
|
|
280
|
-
```
|
|
41
|
+
Mem0 provides a simple and customizable interface for performing memory operations. You can create long-term and short-term memories, search for relevant memories, and manage memory history.
|
|
281
42
|
|
|
282
43
|
## 5. Error Handling
|
|
283
44
|
|
|
284
|
-
The MemoryClient throws errors for any API-related issues. You can catch and handle these errors
|
|
285
|
-
|
|
286
|
-
```javascript
|
|
287
|
-
try {
|
|
288
|
-
const result = await client.add(messages, { user_id: "alex" });
|
|
289
|
-
console.log(result);
|
|
290
|
-
} catch (error) {
|
|
291
|
-
if (error.name === 'APIError') {
|
|
292
|
-
console.error('API Error:', error.message);
|
|
293
|
-
} else {
|
|
294
|
-
console.error('Unexpected error:', error);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
```
|
|
45
|
+
The MemoryClient throws errors for any API-related issues. You can catch and handle these errors effectively.
|
|
298
46
|
|
|
299
47
|
## 6. Using with async/await
|
|
300
48
|
|
|
301
|
-
All methods of the MemoryClient return promises,
|
|
302
|
-
|
|
303
|
-
```javascript
|
|
304
|
-
async function addMemory() {
|
|
305
|
-
try {
|
|
306
|
-
const messages = [
|
|
307
|
-
{ role: "user", content: "Hi, I'm Alex. I'm a vegetarian and I'm allergic to nuts." },
|
|
308
|
-
{ role: "assistant", content: "Hello Alex! I've noted that you're a vegetarian and have a nut allergy. I'll keep this in mind for any food-related recommendations or discussions." }
|
|
309
|
-
];
|
|
310
|
-
const result = await client.add(messages, { user_id: "alex" });
|
|
311
|
-
console.log('Memory added:', result);
|
|
312
|
-
|
|
313
|
-
const searchResult = await client.search("What are Alex's dietary restrictions?", { user_id: "alex" });
|
|
314
|
-
console.log('Search result:', searchResult);
|
|
315
|
-
} catch (error) {
|
|
316
|
-
console.error('Error:', error);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
addMemory();
|
|
321
|
-
```
|
|
49
|
+
All methods of the MemoryClient return promises, allowing for seamless integration with async/await syntax.
|
|
322
50
|
|
|
323
51
|
## 7. Testing the Client
|
|
324
52
|
|
|
325
|
-
To test the MemoryClient in a Node.js environment, you can create a simple script
|
|
326
|
-
|
|
327
|
-
```javascript
|
|
328
|
-
// test-mem0.js
|
|
329
|
-
import MemoryClient from 'mem0ai';
|
|
330
|
-
|
|
331
|
-
const apiKey = 'your-api-key-here';
|
|
332
|
-
const client = new MemoryClient(apiKey);
|
|
333
|
-
|
|
334
|
-
async function testMemoryOperations() {
|
|
335
|
-
try {
|
|
336
|
-
// Add a memory
|
|
337
|
-
const addResult = await client.add([
|
|
338
|
-
{ role: "user", content: "My favorite color is blue." }
|
|
339
|
-
], { user_id: "test-user" });
|
|
340
|
-
console.log('Memory added:', addResult);
|
|
341
|
-
|
|
342
|
-
// Search for memories
|
|
343
|
-
const searchResult = await client.search("What's my favorite color?", { user_id: "test-user" });
|
|
344
|
-
console.log('Search result:', searchResult);
|
|
345
|
-
|
|
346
|
-
// Get all memories
|
|
347
|
-
const allMemories = await client.getAll({ user_id: "test-user" });
|
|
348
|
-
console.log('All memories:', allMemories);
|
|
349
|
-
} catch (error) {
|
|
350
|
-
console.error('Error:', error);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
testMemoryOperations();
|
|
355
|
-
```
|
|
356
|
-
|
|
357
|
-
Run this script using Node.js:
|
|
358
|
-
|
|
359
|
-
```bash
|
|
360
|
-
node test-mem0.js
|
|
361
|
-
```
|
|
362
|
-
|
|
363
|
-
This will perform basic operations (add, search, getAll) and log the results, allowing you to verify that the client is working correctly with your API key.
|
|
364
|
-
|
|
365
|
-
Remember to replace 'your-api-key-here' with your actual Mem0 API key when testing.
|
|
53
|
+
To test the MemoryClient in a Node.js environment, you can create a simple script to verify the functionality of memory operations.
|
|
366
54
|
|
|
367
55
|
## Getting Help
|
|
368
56
|
|
package/dist/index.d.mts
CHANGED
|
@@ -80,6 +80,10 @@ interface Memory {
|
|
|
80
80
|
memory_type?: string;
|
|
81
81
|
score?: number;
|
|
82
82
|
metadata?: any | null;
|
|
83
|
+
owner?: string | null;
|
|
84
|
+
agent_id?: string | null;
|
|
85
|
+
app_id?: string | null;
|
|
86
|
+
run_id?: string | null;
|
|
83
87
|
}
|
|
84
88
|
interface MemoryUpdateBody {
|
|
85
89
|
memoryId: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -80,6 +80,10 @@ interface Memory {
|
|
|
80
80
|
memory_type?: string;
|
|
81
81
|
score?: number;
|
|
82
82
|
metadata?: any | null;
|
|
83
|
+
owner?: string | null;
|
|
84
|
+
agent_id?: string | null;
|
|
85
|
+
app_id?: string | null;
|
|
86
|
+
run_id?: string | null;
|
|
83
87
|
}
|
|
84
88
|
interface MemoryUpdateBody {
|
|
85
89
|
memoryId: string;
|