The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.
Python agentic-memoryagentic-memory-systemagentsaiai-agentschatgptgenaillmlong-term-memorymemorymemory-managementpythonragstate-management
fix: upgrade MongoDB vector store from deprecated knnVector to GA vectorSearch (#3995)
Varun Chawla7cebaba0a22c
diff --git a/mem0/vector_stores/mongodb.py b/mem0/vector_stores/mongodb.pyindex 2bdebf293..7d1e82bb6 100644--- a/mem0/vector_stores/mongodb.py+++ b/mem0/vector_stores/mongodb.py@@ -26,7 +26,7 @@ class OutputData(BaseModel):class MongoDB(VectorStoreBase):- VECTOR_TYPE = "knnVector"+ VECTOR_TYPE = "vector"SIMILARITY_METRIC = "cosine"def __init__(self, db_name: str, collection_name: str, embedding_model_dims: int, mongo_uri: str):@@ -69,17 +69,16 @@ class MongoDB(VectorStoreBase):else:search_index_model = SearchIndexModel(name=self.index_name,+ type="vectorSearch",definition={- "mappings": {- "dynamic": False,- "fields": {- "embedding": {- "type": self.VECTOR_TYPE,- "dimensions": self.embedding_model_dims,- "similarity": self.SIMILARITY_METRIC,- }- },- }+ "fields": [+ {+ "type": self.VECTOR_TYPE,+ "path": "embedding",+ "numDimensions": self.embedding_model_dims,+ "similarity": self.SIMILARITY_METRIC,+ }+ ]},)collection.create_search_index(search_index_model)@@ -141,7 +140,7 @@ class MongoDB(VectorStoreBase):"$vectorSearch": {"index": self.index_name,"limit": limit,- "numCandidates": limit,+ "numCandidates": min(limit * 20, 10000),"queryVector": vectors,"path": "embedding",}diff --git a/tests/vector_stores/test_mongodb.py b/tests/vector_stores/test_mongodb.pyindex bb4b3f69f..d75a05846 100644--- a/tests/vector_stores/test_mongodb.py+++ b/tests/vector_stores/test_mongodb.py@@ -48,17 +48,16 @@ def test_initalize_create_col(mongo_vector_fixture):search_index_model = args[0].documentassert search_index_model == {"name": "test_collection_vector_index",+ "type": "vectorSearch","definition": {- "mappings": {- "dynamic": False,- "fields": {- "embedding": {- "type": "knnVector",- "dimensions": 1536,- "similarity": "cosine",- }- },- }+ "fields": [+ {+ "type": "vector",+ "path": "embedding",+ "numDimensions": 1536,+ "similarity": "cosine",+ }+ ]},}assert mongo_vector.collection == mock_collection@@ -95,7 +94,7 @@ def test_search(mongo_vector_fixture):"$vectorSearch": {"index": "test_collection_vector_index","limit": 2,- "numCandidates": 2,+ "numCandidates": 40,"queryVector": query_vector,"path": "embedding",},