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): return None from Redis.get() for missing IDs (#5625)

ly-wang19c5971193a2c1
diff --git a/mem0/vector_stores/redis.py b/mem0/vector_stores/redis.py
index 80bcb06c6..43bcb04c8 100644
--- a/mem0/vector_stores/redis.py
+++ b/mem0/vector_stores/redis.py
@@ -263,6 +263,8 @@ class RedisDB(VectorStoreBase):
def get(self, vector_id):
result = self.index.fetch(vector_id)
+ if result is None:
+ return None
payload = {
"hash": result["hash"],
"data": result["memory"],
diff --git a/tests/vector_stores/test_redis.py b/tests/vector_stores/test_redis.py
index 1cc76de18..139aaeeb2 100644
--- a/tests/vector_stores/test_redis.py
+++ b/tests/vector_stores/test_redis.py
@@ -113,3 +113,18 @@ def test_list_with_filter_builds_query():
query = mock_index.search.call_args[0][0]
assert query.query_string() == "@user_id:{alice}"
+
+
+def test_get_returns_none_for_missing_id():
+ """get() must return None for a missing id.
+
+ redisvl's SearchIndex.fetch() returns None when the id is not found, so the
+ old code raised ``TypeError: 'NoneType' object is not subscriptable`` on
+ ``result["hash"]``. Every other vector store returns None for a missing id,
+ and Memory relies on it (``if existing_memory is None``), so get() must too.
+ """
+ db, mock_index = _make_redis_db()
+ mock_index.fetch.return_value = None
+
+ assert db.get("missing_id") is None
+ mock_index.fetch.assert_called_once_with("missing_id")