Skip to content

armgit / mem0

Public Imported from GitHub
0

The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.

fix(vector-stores): add agent_id and run_id to Elasticsearch/OpenSearch default mappings (#4906)

jessai2099573e5212a4cc
diff --git a/mem0/vector_stores/elasticsearch.py b/mem0/vector_stores/elasticsearch.py
index 65dcc8942..d3abc2c26 100644
--- a/mem0/vector_stores/elasticsearch.py
+++ b/mem0/vector_stores/elasticsearch.py
@@ -66,7 +66,14 @@ class ElasticsearchDB(VectorStoreBase):
"index": True,
"similarity": "cosine",
},
- "metadata": {"type": "object", "properties": {"user_id": {"type": "keyword"}}},
+ "metadata": {
+ "type": "object",
+ "properties": {
+ "user_id": {"type": "keyword"},
+ "agent_id": {"type": "keyword"},
+ "run_id": {"type": "keyword"},
+ },
+ },
}
},
}
diff --git a/mem0/vector_stores/opensearch.py b/mem0/vector_stores/opensearch.py
index abec64277..c63550cf8 100644
--- a/mem0/vector_stores/opensearch.py
+++ b/mem0/vector_stores/opensearch.py
@@ -55,7 +55,14 @@ class OpenSearchDB(VectorStoreBase):
"dimension": self.embedding_model_dims,
"method": {"engine": "nmslib", "name": "hnsw", "space_type": "cosinesimil"},
},
- "metadata": {"type": "object", "properties": {"user_id": {"type": "keyword"}}},
+ "metadata": {
+ "type": "object",
+ "properties": {
+ "user_id": {"type": "keyword"},
+ "agent_id": {"type": "keyword"},
+ "run_id": {"type": "keyword"},
+ },
+ },
}
},
}
diff --git a/tests/vector_stores/test_elasticsearch.py b/tests/vector_stores/test_elasticsearch.py
index 61ff9efbd..2d92d6da8 100644
--- a/tests/vector_stores/test_elasticsearch.py
+++ b/tests/vector_stores/test_elasticsearch.py
@@ -96,6 +96,10 @@ class TestElasticsearchDB(unittest.TestCase):
self.assertEqual(mappings["vector"]["index"], True)
self.assertEqual(mappings["vector"]["similarity"], "cosine")
self.assertEqual(mappings["metadata"]["type"], "object")
+ metadata_props = mappings["metadata"]["properties"]
+ self.assertEqual(metadata_props["user_id"]["type"], "keyword")
+ self.assertEqual(metadata_props["agent_id"]["type"], "keyword")
+ self.assertEqual(metadata_props["run_id"]["type"], "keyword")
# Reset mocks for next test
self.client_mock.reset_mock()
diff --git a/tests/vector_stores/test_opensearch.py b/tests/vector_stores/test_opensearch.py
index 09046c367..29729e5d2 100644
--- a/tests/vector_stores/test_opensearch.py
+++ b/tests/vector_stores/test_opensearch.py
@@ -142,6 +142,10 @@ class TestOpenSearchDB(unittest.TestCase):
mappings = create_args["body"]["mappings"]["properties"]
self.assertEqual(mappings["vector_field"]["type"], "knn_vector")
self.assertEqual(mappings["vector_field"]["dimension"], 1536)
+ metadata_props = mappings["metadata"]["properties"]
+ self.assertEqual(metadata_props["user_id"]["type"], "keyword")
+ self.assertEqual(metadata_props["agent_id"]["type"], "keyword")
+ self.assertEqual(metadata_props["run_id"]["type"], "keyword")
self.client_mock.reset_mock()
self.client_mock.indices.exists.return_value = True
self.os_db.create_index()