[docs] OSS Features , Overview , Brushup (#3676)

This commit is contained in:
Parth Sharma
2025-10-27 12:31:40 -07:00
committed by GitHub
parent 80c9139c5b
commit ee8955d08b
37 changed files with 1856 additions and 1696 deletions
+211 -368
View File
@@ -1,342 +1,177 @@
---
title: Node SDK Quickstart
description: 'Get started with Mem0 quickly!'
icon: "node"
iconType: "solid"
description: "Store and search Mem0 memories from a TypeScript or JavaScript app in minutes."
icon: "js"
---
> Welcome to the Mem0 quickstart guide. This guide will help you get up and running with Mem0 in no time.
Spin up Mem0 with the Node SDK in just a few steps. You’ll install the package, initialize the client, add a memory, and confirm retrieval with a single search.
## Installation
## Prerequisites
To install Mem0, you can use npm. Run the following command in your terminal:
- Node.js 18 or higher
- (Optional) OpenAI API key stored in your environment when you want to customize providers
## Install and run your first memory
<Steps>
<Step title="Install the SDK">
```bash
npm install mem0ai
```
</Step>
## Basic Usage
### Initialize Mem0
<Tabs>
<Tab title="Basic">
```typescript
import { Memory } from 'mem0ai/oss';
<Step title="Initialize the client">
```ts
import { Memory } from "mem0ai/oss";
const memory = new Memory();
```
</Tab>
<Tab title="Advanced">
If you want to run Mem0 in production, initialize using the following method:
</Step>
```typescript
import { Memory } from 'mem0ai/oss';
const memory = new Memory({
version: 'v1.1',
embedder: {
provider: 'openai',
config: {
apiKey: process.env.OPENAI_API_KEY || '',
model: 'text-embedding-3-small',
},
},
vectorStore: {
provider: 'memory',
config: {
collectionName: 'memories',
dimension: 1536,
},
},
llm: {
provider: 'openai',
config: {
apiKey: process.env.OPENAI_API_KEY || '',
model: 'gpt-4-turbo-preview',
},
},
historyDbPath: 'memory.db',
});
```
</Tab>
</Tabs>
### Store a Memory
<CodeGroup>
```typescript Code
<Step title="Add a memory">
```ts
const messages = [
{"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"},
{"role": "assistant", "content": "How about 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."}
]
{ role: "user", content: "I'm planning to watch a movie tonight. Any recommendations?" },
{ role: "assistant", content: "How about 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" } });
```
</Step>
```json Output
<Step title="Search memories">
```ts
const results = await memory.search("What do you know about me?", { userId: "alice" });
console.log(results);
```
**Output**
```json
{
"results": [
{
"id": "892db2ae-06d9-49e5-8b3e-585ef9b85b8e",
"memory": "User is planning to watch a movie tonight.",
"metadata": {
"category": "movie_recommendations"
}
},
{
"id": "cbb1fe73-0bf1-4067-8c1f-63aa53e7b1a4",
"memory": "User is not a big fan of thriller movies.",
"metadata": {
"category": "movie_recommendations"
}
},
{
"id": "475bde34-21e6-42ab-8bef-0ab84474f156",
"memory": "User loves sci-fi movies.",
"metadata": {
"category": "movie_recommendations"
}
}
]
}
```
</CodeGroup>
### Retrieve Memories
<CodeGroup>
```typescript Code
// Get all memories
const allMemories = await memory.getAll({ userId: "alice" });
console.log(allMemories)
```
```json Output
{
"results": [
{
"id": "892db2ae-06d9-49e5-8b3e-585ef9b85b8e",
"memory": "User is planning to watch a movie tonight.",
"hash": "1a271c007316c94377175ee80e746a19",
"createdAt": "2025-02-27T16:33:20.557Z",
"updatedAt": "2025-02-27T16:33:27.051Z",
"metadata": {
"category": "movie_recommendations"
},
"userId": "alice"
},
{
"id": "475bde34-21e6-42ab-8bef-0ab84474f156",
"memory": "User loves sci-fi movies.",
"hash": "285d07801ae42054732314853e9eadd7",
"createdAt": "2025-02-27T16:33:20.560Z",
"updatedAt": undefined,
"metadata": {
"category": "movie_recommendations"
},
"userId": "alice"
},
{
"id": "cbb1fe73-0bf1-4067-8c1f-63aa53e7b1a4",
"memory": "User is not a big fan of thriller movies.",
"hash": "285d07801ae42054732314853e9eadd7",
"createdAt": "2025-02-27T16:33:20.560Z",
"updatedAt": undefined,
"metadata": {
"category": "movie_recommendations"
},
"userId": "alice"
}
]
}
```
</CodeGroup>
<br />
<CodeGroup>
```typescript Code
// Get a single memory by ID
const singleMemory = await memory.get('892db2ae-06d9-49e5-8b3e-585ef9b85b8e');
console.log(singleMemory);
```
```json Output
{
"id": "892db2ae-06d9-49e5-8b3e-585ef9b85b8e",
"memory": "User is planning to watch a movie tonight.",
"hash": "1a271c007316c94377175ee80e746a19",
"createdAt": "2025-02-27T16:33:20.557Z",
"updatedAt": undefined,
"metadata": {
"category": "movie_recommendations"
},
"userId": "alice"
}
```
</CodeGroup>
### Search Memories
<CodeGroup>
```typescript Code
const result = await memory.search('What do you know about me?', { userId: "alice" });
console.log(result);
```
```json Output
{
"results": [
{
"id": "892db2ae-06d9-49e5-8b3e-585ef9b85b8e",
"memory": "User is planning to watch a movie tonight.",
"hash": "1a271c007316c94377175ee80e746a19",
"createdAt": "2025-02-27T16:33:20.557Z",
"updatedAt": undefined,
"score": 0.38920719231944799,
"metadata": {
"category": "movie_recommendations"
},
"userId": "alice"
},
{
"id": "475bde34-21e6-42ab-8bef-0ab84474f156",
"memory": "User loves sci-fi movies.",
"hash": "285d07801ae42054732314853e9eadd7",
"createdAt": "2025-02-27T16:33:20.560Z",
"updatedAt": undefined,
"score": 0.36869761478135689,
"metadata": {
"category": "movie_recommendations"
},
"userId": "alice"
},
{
"id": "cbb1fe73-0bf1-4067-8c1f-63aa53e7b1a4",
"memory": "User is not a big fan of thriller movies.",
"hash": "285d07801ae42054732314853e9eadd7",
"createdAt": "2025-02-27T16:33:20.560Z",
"updatedAt": undefined,
"score": 0.33855272141248272,
"metadata": {
"category": "movie_recommendations"
},
"userId": "alice"
}
]
}
```
</CodeGroup>
</Step>
</Steps>
### Update a Memory
<Note>
By default the Node SDK uses local-friendly settings (OpenAI `gpt-4.1-nano-2025-04-14`, `text-embedding-3-small`, in-memory vector store, and SQLite history). Swap components by passing a config as shown below.
</Note>
## Configure for production
```ts
import { Memory } from "mem0ai/oss";
const memory = new Memory({
version: "v1.1",
embedder: {
provider: "openai",
config: {
apiKey: process.env.OPENAI_API_KEY || "",
model: "text-embedding-3-small"
}
},
vectorStore: {
provider: "memory",
config: {
collectionName: "memories",
dimension: 1536
}
},
llm: {
provider: "openai",
config: {
apiKey: process.env.OPENAI_API_KEY || "",
model: "gpt-4-turbo-preview"
}
},
historyDbPath: "memory.db"
});
```
## Manage memories (optional)
<CodeGroup>
```typescript Code
const result = await memory.update(
'892db2ae-06d9-49e5-8b3e-585ef9b85b8e',
'I love India, it is my favorite country.'
);
```ts Get all memories
const allMemories = await memory.getAll({ userId: "alice" });
console.log(allMemories);
```
```ts Get one memory
const singleMemory = await memory.get("892db2ae-06d9-49e5-8b3e-585ef9b85b8e");
console.log(singleMemory);
```
```ts Search memories
const result = await memory.search("What do you know about me?", { userId: "alice" });
console.log(result);
```
```json Output
{
"message": "Memory updated successfully!"
}
```ts Update a memory
const updateResult = await memory.update(
"892db2ae-06d9-49e5-8b3e-585ef9b85b8e",
"I love India, it is my favorite country."
);
console.log(updateResult);
```
</CodeGroup>
### Memory History
<CodeGroup>
```typescript Code
const history = await memory.history('892db2ae-06d9-49e5-8b3e-585ef9b85b8e');
```ts
// Audit history
const history = await memory.history("892db2ae-06d9-49e5-8b3e-585ef9b85b8e");
console.log(history);
```
```json Output
[
{
"id": 39,
"memoryId": "892db2ae-06d9-49e5-8b3e-585ef9b85b8e",
"previousValue": "User is planning to watch a movie tonight.",
"newValue": "I love India, it is my favorite country.",
"action": "UPDATE",
"createdAt": "2025-02-27T16:33:20.557Z",
"updatedAt": "2025-02-27T16:33:27.051Z",
"isDeleted": 0
},
{
"id": 37,
"memoryId": "892db2ae-06d9-49e5-8b3e-585ef9b85b8e",
"previousValue": null,
"newValue": "User is planning to watch a movie tonight.",
"action": "ADD",
"createdAt": "2025-02-27T16:33:20.557Z",
"updatedAt": null,
"isDeleted": 0
}
]
```
</CodeGroup>
### Delete Memory
```typescript
// Delete a memory by id
await memory.delete('892db2ae-06d9-49e5-8b3e-585ef9b85b8e');
// Delete all memories for a user
// Delete specific or scoped memories
await memory.delete("892db2ae-06d9-49e5-8b3e-585ef9b85b8e");
await memory.deleteAll({ userId: "alice" });
// Reset everything
await memory.reset();
```
### Reset Memory
## Use a custom history store
```typescript
await memory.reset(); // Reset all memories
```
### History Store
The Mem0 TypeScript SDK supports history stores to run in serverless environments.
We recommend using Supabase as a history store for serverless environments, or disabling the history store to run in serverless environments.
The Node SDK supports Supabase (or other providers) when you need serverless-friendly history storage.
<CodeGroup>
```typescript Supabase
import { Memory } from 'mem0ai/oss';
```ts Supabase provider
import { Memory } from "mem0ai/oss";
const memory = new Memory({
historyStore: {
provider: 'supabase',
provider: "supabase",
config: {
supabaseUrl: process.env.SUPABASE_URL || '',
supabaseKey: process.env.SUPABASE_KEY || '',
tableName: 'memory_history',
},
},
supabaseUrl: process.env.SUPABASE_URL || "",
supabaseKey: process.env.SUPABASE_KEY || "",
tableName: "memory_history"
}
}
});
```
```typescript Disable History
import { Memory } from 'mem0ai/oss';
```ts Disable history
import { Memory } from "mem0ai/oss";
const memory = new Memory({
disableHistory: true,
disableHistory: true
});
```
</CodeGroup>
Mem0 uses SQLite as a default history store.
#### Create Memory History Table in Supabase
You may need to create a memory history table in Supabase to store the history of memories. Use the following SQL command in `SQL Editor` on the Supabase project dashboard to create a memory history table:
Create the Supabase table with:
```sql
create table memory_history (
@@ -351,105 +186,113 @@ create table memory_history (
);
```
## Configuration Parameters
## Configuration parameters
Mem0 offers extensive configuration options to customize its behavior according to your needs. These configurations span different components like vector stores, language models, embedders, and graph stores.
Mem0 offers granular configuration across vector stores, LLMs, embedders, and history stores.
<AccordionGroup>
<Accordion title="Vector Store Configuration">
| Parameter | Description | Default |
|-------------|---------------------------------|-------------|
| `provider` | Vector store provider (e.g., "memory") | "memory" |
| `host` | Host address | "localhost" |
| `port` | Port number | undefined |
</Accordion>
<Accordion title="LLM Configuration">
| Parameter | Description | Provider |
|-----------------------|-----------------------------------------------|-------------------|
| `provider` | LLM provider (e.g., "openai", "anthropic") | All |
| `model` | Model to use | All |
| `temperature` | Temperature of the model | All |
| `apiKey` | API key to use | All |
| `maxTokens` | Tokens to generate | All |
| `topP` | Probability threshold for nucleus sampling | All |
| `topK` | Number of highest probability tokens to keep | All |
| `openaiBaseUrl` | Base URL for OpenAI API | OpenAI |
</Accordion>
<Accordion title="Graph Store Configuration">
| Parameter | Description | Default |
|-------------|---------------------------------|-------------|
| `provider` | Graph store provider (e.g., "neo4j") | "neo4j" |
| `url` | Connection URL | env.NEO4J_URL |
| `username` | Authentication username | env.NEO4J_USERNAME |
| `password` | Authentication password | env.NEO4J_PASSWORD |
</Accordion>
<Accordion title="Embedder Configuration">
| Parameter | Description | Default |
|-------------|---------------------------------|------------------------------|
| `provider` | Embedding provider | "openai" |
| `model` | Embedding model to use | "text-embedding-3-small" |
| `apiKey` | API key for embedding service | None |
</Accordion>
<Accordion title="General Configuration">
| Parameter | Description | Default |
|------------------|--------------------------------------|----------------------------|
| `historyDbPath` | Path to the history database | "{mem0_dir}/history.db" |
| `version` | API version | "v1.0" |
| `customPrompt` | Custom prompt for memory processing | None |
</Accordion>
<Accordion title="History Table Configuration">
| Parameter | Description | Default |
|------------------|--------------------------------------|----------------------------|
| `provider` | History store provider | "sqlite" |
| `config` | History store configuration | None (Defaults to SQLite) |
| `disableHistory` | Disable history store | false |
</Accordion>
<Accordion title="Complete Configuration Example">
```typescript
<Accordion title="Vector store">
| Parameter | Description | Default |
| --- | --- | --- |
| `provider` | Vector store provider (e.g., `"memory"`) | `"memory"` |
| `host` | Host address | `"localhost"` |
| `port` | Port number | `undefined` |
</Accordion>
<Accordion title="LLM">
| Parameter | Description | Provider |
| --- | --- | --- |
| `provider` | LLM provider (e.g., `"openai"`, `"anthropic"`) | All |
| `model` | Model to use | All |
| `temperature` | Temperature value | All |
| `apiKey` | API key | All |
| `maxTokens` | Max tokens to generate | All |
| `topP` | Probability threshold | All |
| `topK` | Token count to keep | All |
| `openaiBaseUrl` | Base URL override | OpenAI |
</Accordion>
<Accordion title="Graph store">
| Parameter | Description | Default |
| --- | --- | --- |
| `provider` | Graph store provider (e.g., `"neo4j"`) | `"neo4j"` |
| `url` | Connection URL | `process.env.NEO4J_URL` |
| `username` | Username | `process.env.NEO4J_USERNAME` |
| `password` | Password | `process.env.NEO4J_PASSWORD` |
</Accordion>
<Accordion title="Embedder">
| Parameter | Description | Default |
| --- | --- | --- |
| `provider` | Embedding provider | `"openai"` |
| `model` | Embedding model | `"text-embedding-3-small"` |
| `apiKey` | API key | `undefined` |
</Accordion>
<Accordion title="General">
| Parameter | Description | Default |
| --- | --- | --- |
| `historyDbPath` | Path to history database | `"{mem0_dir}/history.db"` |
| `version` | API version | `"v1.0"` |
| `customPrompt` | Custom processing prompt | `undefined` |
</Accordion>
<Accordion title="History store">
| Parameter | Description | Default |
| --- | --- | --- |
| `provider` | History provider | `"sqlite"` |
| `config` | Provider configuration | `undefined` |
| `disableHistory` | Disable history store | `false` |
</Accordion>
<Accordion title="Complete config example">
```ts
const config = {
version: 'v1.1',
embedder: {
provider: 'openai',
config: {
apiKey: process.env.OPENAI_API_KEY || '',
model: 'text-embedding-3-small',
},
},
vectorStore: {
provider: 'memory',
config: {
collectionName: 'memories',
dimension: 1536,
},
},
llm: {
provider: 'openai',
config: {
apiKey: process.env.OPENAI_API_KEY || '',
model: 'gpt-4-turbo-preview',
},
},
historyStore: {
provider: 'supabase',
config: {
supabaseUrl: process.env.SUPABASE_URL || '',
supabaseKey: process.env.SUPABASE_KEY || '',
tableName: 'memories',
},
},
disableHistory: false, // This is false by default
customPrompt: "I'm a virtual assistant. I'm here to help you with your queries.",
version: "v1.1",
embedder: {
provider: "openai",
config: {
apiKey: process.env.OPENAI_API_KEY || "",
model: "text-embedding-3-small"
}
},
vectorStore: {
provider: "memory",
config: {
collectionName: "memories",
dimension: 1536
}
},
llm: {
provider: "openai",
config: {
apiKey: process.env.OPENAI_API_KEY || "",
model: "gpt-4-turbo-preview"
}
},
historyStore: {
provider: "supabase",
config: {
supabaseUrl: process.env.SUPABASE_URL || "",
supabaseKey: process.env.SUPABASE_KEY || "",
tableName: "memories"
}
},
disableHistory: false,
customPrompt: "I'm a virtual assistant. I'm here to help you with your queries."
};
```
</Accordion>
</Accordion>
</AccordionGroup>
If you have any questions, please feel free to reach out to us using one of the following methods:
## What's next?
<Snippet file="get-help.mdx" />
<CardGroup cols={3}>
<Card title="Explore Memory Operations" icon="database" href="/open-source/overview">
Review CRUD patterns, filters, and advanced retrieval across the OSS stack.
</Card>
<Card title="Customize Configuration" icon="sliders" href="/open-source/configuration">
Swap in your preferred LLM, vector store, and history provider for production use.
</Card>
<Card title="Automate Node Workflows" icon="plug" href="/cookbooks/integrations/openai-tool-calls">
See a full Node-based workflow that layers Mem0 memories onto tool-calling agents.
</Card>
</CardGroup>
If you have any questions, please feel free to reach out:
<Snippet file="get-help.mdx" />