MongoDB

MongoDB is a versatile document database that supports vector search capabilities, allowing for efficient high-dimensional similarity searches over large datasets with robust scalability and performance.

Usage

import os
from mem0 import Memory

os.environ["OPENAI_API_KEY"] = "sk-xx"

config = {
    "vector_store": {
        "provider": "mongodb",
        "config": {
            "db_name": "mem0-db",
            "collection_name": "mem0-collection",
            "user": "my-user",
            "password": "my-password",
        }
    }
}

m = Memory.from_config(config)
messages = [
    {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"},
    {"role": "assistant", "content": "How about a 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."}
]
m.add(messages, user_id="alice", metadata={"category": "movies"})

Config

Here are the parameters available for configuring MongoDB:

ParameterDescriptionDefault Value
db_nameName of the MongoDB database"mem0_db"
collection_nameName of the MongoDB collection"mem0_collection"
embedding_model_dimsDimensions of the embedding vectors1536
userMongoDB user for authenticationNone
passwordPassword for the MongoDB userNone
hostMongoDB host"localhost"
portMongoDB port27017

Note: user and password must either be provided together or omitted together.