Skip to content

fix(memory): isolate in-memory long-term memory per user - #1200

Open
eric7h wants to merge 2 commits into
volcengine:mainfrom
eric7h:fix/in-memory-ltm-user-isolation
Open

eric7h wants to merge 2 commits into
volcengine:mainfrom
eric7h:fix/in-memory-ltm-user-isolation

Conversation

@eric7h

@eric7h eric7h commented Nov 3, 2026

Copy link
Copy Markdown

Problem

InMemoryLTMBackend (LongTermMemory(backend="local")) ignores user_id. save_memory writes every user's events into one shared VectorStoreIndex, and search_memory searches that shared index, so one user's memories are returned to another user. The other backends (Redis, OpenSearch, ...) build a separate index per veadk-ltm/{index}/{user_id}.

Reproduction

backend.save_memory(user_id="alice", event_strings=["alice likes tea"])
backend.save_memory(user_id="bob", event_strings=["bob likes coffee"])
backend.search_memory(user_id="carol", query="likes", top_k=5)
# main: ['alice likes tea']   expected: []

Fix

Keep one in-memory VectorStoreIndex per user_id. Searching for a user with no saved memories returns [].

Verification

  • New tests/memory/long_term_memory_backends/test_in_memory_ltm_backend.py (uses llama_index MockEmbedding, no network): both tests fail on main and pass with the fix.
  • 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": 8054 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. Only the local backend's behavior changes: memories are now scoped per user, like the other backends.

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