import "dotenv/config";
import { Memory } from "mem0ai/oss";
const m = new Memory({
vectorStore: {
provider: "pgvector",
config: {
connectionString: process.env.DATABASE_URL!,
ssl: {
rejectUnauthorized: false,
},
collectionName: "memories",
dimension: 1536,
embeddingModelDims: 1536,
hnsw: true,
},
},
});
const messages = [
{ role: "user" as const, content: "I'm planning to watch a movie tonight. Any recommendations?" },
{ role: "assistant" as const, content: "How about thriller movies? They can be quite engaging." },
{ role: "user" as const, content: "I'm not a big fan of thriller movies but I love sci-fi movies." },
{ role: "assistant" as const, content: "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future." },
];
await m.add(messages, {
userId: "alice",
metadata: { category: "movies" },
});
const results = await m.search("What movies should I recommend?", {
filters: { user_id: "alice" },
});
console.log(results);