docs/open-source/node-quickstart.mdx
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.
const memory = new Memory();
</Step>
<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." }
];
await memory.add(messages, { userId: "alice", metadata: { category: "movie_recommendations" } });
Output
{
"results": [
{
"id": "892db2ae-06d9-49e5-8b3e-585ef9b85b8e",
"memory": "User is planning to watch a movie tonight.",
"score": 0.38920719231944799,
"metadata": {
"category": "movie_recommendations"
},
"userId": "alice"
}
]
}
Pass a config object to new Memory() to use your own LLM, embedder, and vector store:
import { Memory } from "mem0ai/oss";
const memory = new Memory({
llm: {
provider: "openai",
config: { apiKey: process.env.OPENAI_API_KEY || "", model: "gpt-4-turbo-preview" }
},
embedder: {
provider: "openai",
config: { apiKey: process.env.OPENAI_API_KEY || "", model: "text-embedding-3-small" }
},
vectorStore: {
provider: "memory",
config: { collectionName: "memories", dimension: 1536 }
}
});
For the full provider catalog, history stores, and every config option, see Configuration.
If you have any questions, please feel free to reach out:
<Snippet file="get-help.mdx" />