Skip to content

fix(memory): stop Redis long-term memory indexes matching other users' keys - #1201

Open
eric7h wants to merge 1 commit into
volcengine:mainfrom
eric7h:fix/redis-ltm-user-prefix
Open

eric7h wants to merge 1 commit into
volcengine:mainfrom
eric7h:fix/redis-ltm-user-prefix

Conversation

@eric7h

@eric7h eric7h commented Nov 3, 2026

Copy link
Copy Markdown

Problem

RedisLTMBackend creates one RediSearch index per user, named veadk-ltm/{index}/{user_id}, with prefix set to the same string and key_separator="_". RediSearch indexes every key that starts with the prefix, so the index of user u1 (prefix veadk-ltm/app/u1) also indexes the keys of user u10 (veadk-ltm/app/u10_<id>), u100, u1abc, and so on. search_memory(user_id="u1", ...) then returns other users' memories.

Reproduction (real Redis Stack 7.4, MockEmbedding)

backend = RedisLTMBackend(index="repro", redis_config=..., embedding_config=EmbeddingModelConfig(dim=8))
backend.save_memory("u10", ["u10 secret"])
backend.search_memory("u1", "secret", 5)
# main: ['u10 secret']   expected: []

On main the u1 query logs Found 1 results ... ['veadk-ltm/repro/u10_5ecec7c3-...'].

Fix

  • The index prefix is now {index}_ with an empty key_separator. Stored keys keep the exact {index}_{id} format, so existing memories are still found.
  • Indexes created by older versions keep their old prefix (RedisVectorStore doesn't redefine an existing index). Before creating the vector store, the backend reads FT.INFO. If the prefix is stale, it drops only the index definition (FT.DROPINDEX without DD, so no data is deleted), and the index is recreated with the correct prefix. RediSearch then re-indexes the existing keys.

Re-running the reproduction against the same Redis after the fix: u1 no longer sees u10's memory, u10 still finds its own old memories, and FT.INFO veadk-ltm/repro/u1 shows prefixes: ['veadk-ltm/repro/u1_'].

Verification

  • New tests/memory/long_term_memory_backends/test_redis_ltm_backend.py uses fake Redis and vector store objects, so it needs no server. 2 of the 4 tests fail on main (prefix overlap, stale index not redefined) and all 4 pass with the fix.
  • Manual check against a local Redis Stack 7.4.0 server, as described above.
  • uv run --extra dev pre-commit run --all-files: pass.
  • uv run --extra dev pytest -n 4 -m "not codex_smoke and not piagent_smoke": 8056 passed. The same 24 failures and 2 collection errors (Codex runtime / self-host sandbox tests that need local tooling) occur on unmodified main in this environment.

Impact

No public API change. On first use after upgrading, each existing user index is redefined once (data kept) and re-indexed by Redis in the background.

This PR was prepared with an AI coding agent; I authorized the submission.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant