From 573e5212a4ccecffdbda2162db8efd0b7211cf79 Mon Sep 17 00:00:00 2001 From: jessai2099 Date: Tue, 21 Apr 2026 01:40:59 +0800 Subject: [PATCH] fix(vector-stores): add agent_id and run_id to Elasticsearch/OpenSearch default mappings (#4906) Co-authored-by: Claude Sonnet 4.6 --- mem0/vector_stores/elasticsearch.py | 9 ++++++++- mem0/vector_stores/opensearch.py | 9 ++++++++- tests/vector_stores/test_elasticsearch.py | 4 ++++ tests/vector_stores/test_opensearch.py | 4 ++++ 4 files changed, 24 insertions(+), 2 deletions(-) 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()