From c5971193a2c16104deb2089de9c86549a3b74bf7 Mon Sep 17 00:00:00 2001 From: ly-wang19 <94427531+ly-wang19@users.noreply.github.com> Date: Fri, 19 Jun 2026 14:55:24 +0800 Subject: [PATCH] fix(vector_stores): return None from Redis.get() for missing IDs (#5625) Co-authored-by: ly-wang19 Co-authored-by: Kartik --- mem0/vector_stores/redis.py | 2 ++ tests/vector_stores/test_redis.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+) 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")