@zibby/mem0ai 2.4.7
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 +64 -0
- package/dist/index.d.mts +364 -0
- package/dist/index.d.ts +364 -0
- package/dist/index.js +863 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +815 -0
- package/dist/index.mjs.map +1 -0
- package/dist/oss/index.d.mts +1026 -0
- package/dist/oss/index.d.ts +1026 -0
- package/dist/oss/index.js +5566 -0
- package/dist/oss/index.js.map +1 -0
- package/dist/oss/index.mjs +5509 -0
- package/dist/oss/index.mjs.map +1 -0
- package/package.json +141 -0
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Mem0 - The Memory Layer for Your AI Apps
|
|
2
|
+
|
|
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.
|
|
4
|
+
|
|
5
|
+
See the complete [OSS Docs](https://docs.mem0.ai/open-source/node-quickstart).
|
|
6
|
+
See the complete [Platform API Reference](https://docs.mem0.ai/api-reference).
|
|
7
|
+
|
|
8
|
+
## 1. Installation
|
|
9
|
+
|
|
10
|
+
For the open-source version, you can install the Mem0 package using npm:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm i mem0ai
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## 2. API Key Setup
|
|
17
|
+
|
|
18
|
+
For the cloud offering, sign in to [Mem0 Platform](https://app.mem0.ai/dashboard/api-keys) to obtain your API Key.
|
|
19
|
+
|
|
20
|
+
## 3. Client Features
|
|
21
|
+
|
|
22
|
+
### Cloud Offering
|
|
23
|
+
|
|
24
|
+
The cloud version provides a comprehensive set of features, including:
|
|
25
|
+
|
|
26
|
+
- **Memory Operations**: Perform CRUD operations on memories.
|
|
27
|
+
- **Search Capabilities**: Search for relevant memories using advanced filters.
|
|
28
|
+
- **Memory History**: Track changes to memories over time.
|
|
29
|
+
- **Error Handling**: Robust error handling for API-related issues.
|
|
30
|
+
- **Async/Await Support**: All methods return promises for easy integration.
|
|
31
|
+
|
|
32
|
+
### Open-Source Offering
|
|
33
|
+
|
|
34
|
+
The open-source version includes the following top features:
|
|
35
|
+
|
|
36
|
+
- **Memory Management**: Add, update, delete, and retrieve memories.
|
|
37
|
+
- **Vector Store Integration**: Supports various vector store providers for efficient memory retrieval.
|
|
38
|
+
- **LLM Support**: Integrates with multiple LLM providers for generating responses.
|
|
39
|
+
- **Customizable Configuration**: Easily configure memory settings and providers.
|
|
40
|
+
- **SQLite Storage**: Use SQLite for memory history management.
|
|
41
|
+
|
|
42
|
+
## 4. Memory Operations
|
|
43
|
+
|
|
44
|
+
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.
|
|
45
|
+
|
|
46
|
+
## 5. Error Handling
|
|
47
|
+
|
|
48
|
+
The MemoryClient throws errors for any API-related issues. You can catch and handle these errors effectively.
|
|
49
|
+
|
|
50
|
+
## 6. Using with async/await
|
|
51
|
+
|
|
52
|
+
All methods of the MemoryClient return promises, allowing for seamless integration with async/await syntax.
|
|
53
|
+
|
|
54
|
+
## 7. Testing the Client
|
|
55
|
+
|
|
56
|
+
To test the MemoryClient in a Node.js environment, you can create a simple script to verify the functionality of memory operations.
|
|
57
|
+
|
|
58
|
+
## Getting Help
|
|
59
|
+
|
|
60
|
+
If you have any questions or need assistance, please reach out to us:
|
|
61
|
+
|
|
62
|
+
- Email: founders@mem0.ai
|
|
63
|
+
- [Join our discord community](https://mem0.ai/discord)
|
|
64
|
+
- GitHub Issues: [Report bugs or request features](https://github.com/mem0ai/mem0/issues)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
interface Common {
|
|
2
|
+
project_id?: string | null;
|
|
3
|
+
org_id?: string | null;
|
|
4
|
+
}
|
|
5
|
+
interface MemoryOptions {
|
|
6
|
+
api_version?: API_VERSION | string;
|
|
7
|
+
version?: API_VERSION | string;
|
|
8
|
+
user_id?: string;
|
|
9
|
+
agent_id?: string;
|
|
10
|
+
app_id?: string;
|
|
11
|
+
run_id?: string;
|
|
12
|
+
metadata?: Record<string, any>;
|
|
13
|
+
filters?: Record<string, any>;
|
|
14
|
+
org_name?: string | null;
|
|
15
|
+
project_name?: string | null;
|
|
16
|
+
org_id?: string | number | null;
|
|
17
|
+
project_id?: string | number | null;
|
|
18
|
+
infer?: boolean;
|
|
19
|
+
page?: number;
|
|
20
|
+
page_size?: number;
|
|
21
|
+
includes?: string;
|
|
22
|
+
excludes?: string;
|
|
23
|
+
enable_graph?: boolean;
|
|
24
|
+
start_date?: string;
|
|
25
|
+
end_date?: string;
|
|
26
|
+
custom_categories?: custom_categories[];
|
|
27
|
+
custom_instructions?: string;
|
|
28
|
+
timestamp?: number;
|
|
29
|
+
output_format?: string | OutputFormat;
|
|
30
|
+
async_mode?: boolean;
|
|
31
|
+
filter_memories?: boolean;
|
|
32
|
+
immutable?: boolean;
|
|
33
|
+
structured_data_schema?: Record<string, any>;
|
|
34
|
+
}
|
|
35
|
+
interface ProjectOptions {
|
|
36
|
+
fields?: string[];
|
|
37
|
+
}
|
|
38
|
+
declare enum OutputFormat {
|
|
39
|
+
V1 = "v1.0",
|
|
40
|
+
V1_1 = "v1.1"
|
|
41
|
+
}
|
|
42
|
+
declare enum API_VERSION {
|
|
43
|
+
V1 = "v1",
|
|
44
|
+
V2 = "v2"
|
|
45
|
+
}
|
|
46
|
+
declare enum Feedback {
|
|
47
|
+
POSITIVE = "POSITIVE",
|
|
48
|
+
NEGATIVE = "NEGATIVE",
|
|
49
|
+
VERY_NEGATIVE = "VERY_NEGATIVE"
|
|
50
|
+
}
|
|
51
|
+
interface MultiModalMessages {
|
|
52
|
+
type: "image_url";
|
|
53
|
+
image_url: {
|
|
54
|
+
url: string;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
interface Messages {
|
|
58
|
+
role: "user" | "assistant";
|
|
59
|
+
content: string | MultiModalMessages;
|
|
60
|
+
}
|
|
61
|
+
interface Message extends Messages {
|
|
62
|
+
}
|
|
63
|
+
interface MemoryHistory {
|
|
64
|
+
id: string;
|
|
65
|
+
memory_id: string;
|
|
66
|
+
input: Array<Messages>;
|
|
67
|
+
old_memory: string | null;
|
|
68
|
+
new_memory: string | null;
|
|
69
|
+
user_id: string;
|
|
70
|
+
categories: Array<string>;
|
|
71
|
+
event: Event | string;
|
|
72
|
+
created_at: Date;
|
|
73
|
+
updated_at: Date;
|
|
74
|
+
}
|
|
75
|
+
interface SearchOptions extends MemoryOptions {
|
|
76
|
+
api_version?: API_VERSION | string;
|
|
77
|
+
limit?: number;
|
|
78
|
+
enable_graph?: boolean;
|
|
79
|
+
threshold?: number;
|
|
80
|
+
top_k?: number;
|
|
81
|
+
only_metadata_based_search?: boolean;
|
|
82
|
+
keyword_search?: boolean;
|
|
83
|
+
fields?: string[];
|
|
84
|
+
categories?: string[];
|
|
85
|
+
rerank?: boolean;
|
|
86
|
+
}
|
|
87
|
+
declare enum Event {
|
|
88
|
+
ADD = "ADD",
|
|
89
|
+
UPDATE = "UPDATE",
|
|
90
|
+
DELETE = "DELETE",
|
|
91
|
+
NOOP = "NOOP"
|
|
92
|
+
}
|
|
93
|
+
interface MemoryData {
|
|
94
|
+
memory: string;
|
|
95
|
+
}
|
|
96
|
+
interface Memory {
|
|
97
|
+
id: string;
|
|
98
|
+
messages?: Array<Messages>;
|
|
99
|
+
event?: Event | string;
|
|
100
|
+
data?: MemoryData | null;
|
|
101
|
+
memory?: string;
|
|
102
|
+
user_id?: string;
|
|
103
|
+
hash?: string;
|
|
104
|
+
categories?: Array<string>;
|
|
105
|
+
created_at?: Date;
|
|
106
|
+
updated_at?: Date;
|
|
107
|
+
memory_type?: string;
|
|
108
|
+
score?: number;
|
|
109
|
+
metadata?: any | null;
|
|
110
|
+
owner?: string | null;
|
|
111
|
+
agent_id?: string | null;
|
|
112
|
+
app_id?: string | null;
|
|
113
|
+
run_id?: string | null;
|
|
114
|
+
}
|
|
115
|
+
interface MemoryUpdateBody {
|
|
116
|
+
memoryId: string;
|
|
117
|
+
text: string;
|
|
118
|
+
}
|
|
119
|
+
interface User {
|
|
120
|
+
id: string;
|
|
121
|
+
name: string;
|
|
122
|
+
created_at: Date;
|
|
123
|
+
updated_at: Date;
|
|
124
|
+
total_memories: number;
|
|
125
|
+
owner: string;
|
|
126
|
+
type: string;
|
|
127
|
+
}
|
|
128
|
+
interface AllUsers {
|
|
129
|
+
count: number;
|
|
130
|
+
results: Array<User>;
|
|
131
|
+
next: any;
|
|
132
|
+
previous: any;
|
|
133
|
+
}
|
|
134
|
+
interface ProjectResponse {
|
|
135
|
+
custom_instructions?: string;
|
|
136
|
+
custom_categories?: string[];
|
|
137
|
+
[key: string]: any;
|
|
138
|
+
}
|
|
139
|
+
interface custom_categories {
|
|
140
|
+
[key: string]: any;
|
|
141
|
+
}
|
|
142
|
+
interface PromptUpdatePayload {
|
|
143
|
+
custom_instructions?: string;
|
|
144
|
+
custom_categories?: custom_categories[];
|
|
145
|
+
retrieval_criteria?: any[];
|
|
146
|
+
enable_graph?: boolean;
|
|
147
|
+
version?: string;
|
|
148
|
+
inclusion_prompt?: string;
|
|
149
|
+
exclusion_prompt?: string;
|
|
150
|
+
memory_depth?: string | null;
|
|
151
|
+
usecase_setting?: string | number;
|
|
152
|
+
multilingual?: boolean;
|
|
153
|
+
[key: string]: any;
|
|
154
|
+
}
|
|
155
|
+
declare enum WebhookEvent {
|
|
156
|
+
MEMORY_ADDED = "memory_add",
|
|
157
|
+
MEMORY_UPDATED = "memory_update",
|
|
158
|
+
MEMORY_DELETED = "memory_delete",
|
|
159
|
+
MEMORY_CATEGORIZED = "memory_categorize"
|
|
160
|
+
}
|
|
161
|
+
interface Webhook {
|
|
162
|
+
webhook_id?: string;
|
|
163
|
+
name: string;
|
|
164
|
+
url: string;
|
|
165
|
+
project?: string;
|
|
166
|
+
created_at?: Date;
|
|
167
|
+
updated_at?: Date;
|
|
168
|
+
is_active?: boolean;
|
|
169
|
+
event_types?: WebhookEvent[];
|
|
170
|
+
}
|
|
171
|
+
interface WebhookCreatePayload {
|
|
172
|
+
name: string;
|
|
173
|
+
url: string;
|
|
174
|
+
eventTypes: WebhookEvent[];
|
|
175
|
+
}
|
|
176
|
+
interface WebhookUpdatePayload {
|
|
177
|
+
webhookId: string;
|
|
178
|
+
name?: string;
|
|
179
|
+
url?: string;
|
|
180
|
+
eventTypes?: WebhookEvent[];
|
|
181
|
+
}
|
|
182
|
+
interface FeedbackPayload {
|
|
183
|
+
memory_id: string;
|
|
184
|
+
feedback?: Feedback | null;
|
|
185
|
+
feedback_reason?: string | null;
|
|
186
|
+
}
|
|
187
|
+
interface CreateMemoryExportPayload extends Common {
|
|
188
|
+
schema: Record<string, any>;
|
|
189
|
+
filters: Record<string, any>;
|
|
190
|
+
export_instructions?: string;
|
|
191
|
+
}
|
|
192
|
+
interface GetMemoryExportPayload extends Common {
|
|
193
|
+
filters?: Record<string, any>;
|
|
194
|
+
memory_export_id?: string;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
interface ClientOptions {
|
|
198
|
+
apiKey: string;
|
|
199
|
+
host?: string;
|
|
200
|
+
organizationName?: string;
|
|
201
|
+
projectName?: string;
|
|
202
|
+
organizationId?: string;
|
|
203
|
+
projectId?: string;
|
|
204
|
+
}
|
|
205
|
+
declare class MemoryClient {
|
|
206
|
+
apiKey: string;
|
|
207
|
+
host: string;
|
|
208
|
+
organizationName: string | null;
|
|
209
|
+
projectName: string | null;
|
|
210
|
+
organizationId: string | number | null;
|
|
211
|
+
projectId: string | number | null;
|
|
212
|
+
headers: Record<string, string>;
|
|
213
|
+
client: any;
|
|
214
|
+
telemetryId: string;
|
|
215
|
+
_validateApiKey(): any;
|
|
216
|
+
_validateOrgProject(): void;
|
|
217
|
+
constructor(options: ClientOptions);
|
|
218
|
+
private _initializeClient;
|
|
219
|
+
private _captureEvent;
|
|
220
|
+
_fetchWithErrorHandling(url: string, options: any): Promise<any>;
|
|
221
|
+
_preparePayload(messages: Array<Message>, options: MemoryOptions): object;
|
|
222
|
+
_prepareParams(options: MemoryOptions): object;
|
|
223
|
+
ping(): Promise<void>;
|
|
224
|
+
add(messages: Array<Message>, options?: MemoryOptions & Record<string, any>): Promise<Array<Memory>>;
|
|
225
|
+
update(memoryId: string, { text, metadata, timestamp, }: {
|
|
226
|
+
text?: string;
|
|
227
|
+
metadata?: Record<string, any>;
|
|
228
|
+
timestamp?: number | string;
|
|
229
|
+
}): Promise<Array<Memory>>;
|
|
230
|
+
get(memoryId: string): Promise<Memory>;
|
|
231
|
+
getAll(options?: SearchOptions): Promise<Array<Memory>>;
|
|
232
|
+
search(query: string, options?: SearchOptions & Record<string, any>): Promise<Array<Memory>>;
|
|
233
|
+
delete(memoryId: string): Promise<{
|
|
234
|
+
message: string;
|
|
235
|
+
}>;
|
|
236
|
+
deleteAll(options?: MemoryOptions): Promise<{
|
|
237
|
+
message: string;
|
|
238
|
+
}>;
|
|
239
|
+
history(memoryId: string): Promise<Array<MemoryHistory>>;
|
|
240
|
+
users(): Promise<AllUsers>;
|
|
241
|
+
/**
|
|
242
|
+
* @deprecated The method should not be used, use `deleteUsers` instead. This will be removed in version 2.2.0.
|
|
243
|
+
*/
|
|
244
|
+
deleteUser(data: {
|
|
245
|
+
entity_id: number;
|
|
246
|
+
entity_type: string;
|
|
247
|
+
}): Promise<{
|
|
248
|
+
message: string;
|
|
249
|
+
}>;
|
|
250
|
+
deleteUsers(params?: {
|
|
251
|
+
user_id?: string;
|
|
252
|
+
agent_id?: string;
|
|
253
|
+
app_id?: string;
|
|
254
|
+
run_id?: string;
|
|
255
|
+
}): Promise<{
|
|
256
|
+
message: string;
|
|
257
|
+
}>;
|
|
258
|
+
batchUpdate(memories: Array<MemoryUpdateBody>): Promise<string>;
|
|
259
|
+
batchDelete(memories: Array<string>): Promise<string>;
|
|
260
|
+
getProject(options: ProjectOptions): Promise<ProjectResponse>;
|
|
261
|
+
updateProject(prompts: PromptUpdatePayload): Promise<Record<string, any>>;
|
|
262
|
+
getWebhooks(data?: {
|
|
263
|
+
projectId?: string;
|
|
264
|
+
}): Promise<Array<Webhook>>;
|
|
265
|
+
createWebhook(webhook: WebhookCreatePayload): Promise<Webhook>;
|
|
266
|
+
updateWebhook(webhook: WebhookUpdatePayload): Promise<{
|
|
267
|
+
message: string;
|
|
268
|
+
}>;
|
|
269
|
+
deleteWebhook(data: {
|
|
270
|
+
webhookId: string;
|
|
271
|
+
}): Promise<{
|
|
272
|
+
message: string;
|
|
273
|
+
}>;
|
|
274
|
+
feedback(data: FeedbackPayload): Promise<{
|
|
275
|
+
message: string;
|
|
276
|
+
}>;
|
|
277
|
+
createMemoryExport(data: CreateMemoryExportPayload): Promise<{
|
|
278
|
+
message: string;
|
|
279
|
+
id: string;
|
|
280
|
+
}>;
|
|
281
|
+
getMemoryExport(data: GetMemoryExportPayload): Promise<{
|
|
282
|
+
message: string;
|
|
283
|
+
id: string;
|
|
284
|
+
}>;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Structured exception classes for mem0 TypeScript SDK.
|
|
289
|
+
*
|
|
290
|
+
* Provides specific, actionable exceptions with error codes, suggestions,
|
|
291
|
+
* and debug information. Maps HTTP status codes to appropriate exception types.
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```typescript
|
|
295
|
+
* import { RateLimitError, MemoryNotFoundError } from 'mem0ai'
|
|
296
|
+
*
|
|
297
|
+
* try {
|
|
298
|
+
* await client.get(memoryId)
|
|
299
|
+
* } catch (e) {
|
|
300
|
+
* if (e instanceof MemoryNotFoundError) {
|
|
301
|
+
* console.log(e.suggestion) // "The requested resource was not found"
|
|
302
|
+
* } else if (e instanceof RateLimitError) {
|
|
303
|
+
* await sleep(e.debugInfo.retryAfter ?? 60)
|
|
304
|
+
* }
|
|
305
|
+
* }
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
interface MemoryErrorOptions {
|
|
309
|
+
details?: Record<string, unknown>;
|
|
310
|
+
suggestion?: string;
|
|
311
|
+
debugInfo?: Record<string, unknown>;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Base exception for all memory-related errors.
|
|
315
|
+
*
|
|
316
|
+
* Every mem0 exception includes an error code for programmatic handling,
|
|
317
|
+
* optional details, a user-friendly suggestion, and debug information.
|
|
318
|
+
*/
|
|
319
|
+
declare class MemoryError extends Error {
|
|
320
|
+
readonly errorCode: string;
|
|
321
|
+
readonly details: Record<string, unknown>;
|
|
322
|
+
readonly suggestion?: string;
|
|
323
|
+
readonly debugInfo: Record<string, unknown>;
|
|
324
|
+
constructor(message: string, errorCode: string, options?: MemoryErrorOptions);
|
|
325
|
+
}
|
|
326
|
+
/** Raised when authentication fails (401, 403). */
|
|
327
|
+
declare class AuthenticationError extends MemoryError {
|
|
328
|
+
constructor(message: string, errorCode: string, options?: MemoryErrorOptions);
|
|
329
|
+
}
|
|
330
|
+
/** Raised when rate limits are exceeded (429). */
|
|
331
|
+
declare class RateLimitError extends MemoryError {
|
|
332
|
+
constructor(message: string, errorCode: string, options?: MemoryErrorOptions);
|
|
333
|
+
}
|
|
334
|
+
/** Raised when input validation fails (400, 409, 422). */
|
|
335
|
+
declare class ValidationError extends MemoryError {
|
|
336
|
+
constructor(message: string, errorCode: string, options?: MemoryErrorOptions);
|
|
337
|
+
}
|
|
338
|
+
/** Raised when a memory is not found (404). */
|
|
339
|
+
declare class MemoryNotFoundError extends MemoryError {
|
|
340
|
+
constructor(message: string, errorCode: string, options?: MemoryErrorOptions);
|
|
341
|
+
}
|
|
342
|
+
/** Raised when network connectivity issues occur (408, 502, 503, 504). */
|
|
343
|
+
declare class NetworkError extends MemoryError {
|
|
344
|
+
constructor(message: string, errorCode: string, options?: MemoryErrorOptions);
|
|
345
|
+
}
|
|
346
|
+
/** Raised when client configuration is invalid. */
|
|
347
|
+
declare class ConfigurationError extends MemoryError {
|
|
348
|
+
constructor(message: string, errorCode: string, options?: MemoryErrorOptions);
|
|
349
|
+
}
|
|
350
|
+
/** Raised when memory quota is exceeded (413). */
|
|
351
|
+
declare class MemoryQuotaExceededError extends MemoryError {
|
|
352
|
+
constructor(message: string, errorCode: string, options?: MemoryErrorOptions);
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Create an appropriate exception based on HTTP response status code.
|
|
356
|
+
*
|
|
357
|
+
* @param statusCode - HTTP status code from the response
|
|
358
|
+
* @param responseText - Response body text
|
|
359
|
+
* @param options - Additional error context (details, debugInfo)
|
|
360
|
+
* @returns An instance of the appropriate MemoryError subclass
|
|
361
|
+
*/
|
|
362
|
+
declare function createExceptionFromResponse(statusCode: number, responseText: string, options?: Omit<MemoryErrorOptions, "suggestion">): MemoryError;
|
|
363
|
+
|
|
364
|
+
export { type AllUsers, AuthenticationError, ConfigurationError, Feedback, type FeedbackPayload, type Memory, MemoryClient, MemoryError, type MemoryErrorOptions, type MemoryHistory, MemoryNotFoundError, type MemoryOptions, MemoryQuotaExceededError, type MemoryUpdateBody, type Message, type Messages, NetworkError, type ProjectOptions, type ProjectResponse, type PromptUpdatePayload, RateLimitError, type SearchOptions, type User, ValidationError, type Webhook, type WebhookCreatePayload, WebhookEvent, type WebhookUpdatePayload, createExceptionFromResponse, MemoryClient as default };
|