Each fix verified against mem0/vector_stores/ source and configs:
- baidu: table_name default mem0_table → mem0 (BaiduDBConfig)
- langchain: TS import mem0ai → mem0ai/oss; fix undefined LangchainVectorStore
variable to use MemoryVectorStore directly
- mongodb: collection_name default mem0_collection → mem0; mongo_uri default
corrected to mongodb://localhost:27017 (MongoDBConfig)
- neon: hnsw default False → True (PGVectorConfig.hnsw = True)
- neptune_analytics: extra name vector_stores → vector-stores (pyproject.toml)
- pgvector: diskann default True → False; hnsw default False → True
(PGVectorConfig)
- upstash-vector: move enable_embeddings inside config: {} block
(UpstashVectorConfig field, not top-level VectorStoreConfig)
- valkey: remove non-existent distance_metric row (not in ValkeyConfig);
fix extra name vector_stores → vector-stores
- vertex_ai: region is required (no default in GoogleMatchingEngineConfig)
- weaviate: install pip install weaviate weaviate-client → weaviate-client
(weaviate is not a separate package)
- overview: update TS supported vector DBs list to reflect actual
mem0-ts/src/oss/src/vector_stores/ files
50 lines
1.7 KiB
Plaintext
50 lines
1.7 KiB
Plaintext
---
|
||
title: "MongoDB"
|
||
description: "Use MongoDB as a vector database in Mem0 with built-in vector search for high-dimensional similarity queries."
|
||
---
|
||
# MongoDB
|
||
|
||
[MongoDB](https://www.mongodb.com/) 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
|
||
|
||
```python
|
||
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",
|
||
"mongo_uri":"mongodb://username:password@localhost:27017"
|
||
}
|
||
}
|
||
}
|
||
|
||
m = Memory.from_config(config)
|
||
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."}
|
||
]
|
||
m.add(messages, user_id="alice", metadata={"category": "movies"})
|
||
```
|
||
|
||
## Config
|
||
|
||
Here are the parameters available for configuring MongoDB:
|
||
|
||
| Parameter | Description | Default Value |
|
||
| --- | --- | --- |
|
||
| db_name | Name of the MongoDB database | `"mem0_db"` |
|
||
| collection_name | Name of the MongoDB collection | `"mem0"` |
|
||
| embedding_model_dims | Dimensions of the embedding vectors | `1536` |
|
||
| mongo_uri | The MongoDB URI connection string | `mongodb://localhost:27017` |
|
||
|
||
> **Note**: If `mongo_uri` is not provided, it will default to `mongodb://localhost:27017`.
|