Skip to content

feat: add valkey memory#3

Merged
edlng merged 3 commits into
add-valkeyfrom
add-valkey-memory
Jun 5, 2026
Merged

feat: add valkey memory#3
edlng merged 3 commits into
add-valkeyfrom
add-valkey-memory

Conversation

@edlng

@edlng edlng commented Jun 5, 2026

Copy link
Copy Markdown
Owner

Summary

Adds a working ValkeyMemory implementation backed by Valkey Search (HNSW vector index) and switches the optional dependency from the async valkey-glide to the synchronous valkey-glide-sync client, which fits the current runtime's blocking call patterns.

Issue

N/A

Changes

  • runtime/node/agent/memory/valkey_memory.py — new file implementing ValkeyMemory. Stores each memory item as a Valkey Hash with content, embedding (float32), agent role, and timestamp. Creates an FT index with HNSW COSINE metric at init. Retrieval uses KNN search and converts cosine distance to similarity for threshold filtering.
  • entity/configs/node/memory.py — added optional username field to ValkeyMemoryConfig for ACL-based auth; wired it through from_dict and field_specs.
  • pyproject.toml — changed optional dep from valkey-glide>=2.4 to valkey-glide-sync>=2.4.
  • tests/test_valkey_memory.py — replaced the skip-always integration skeleton with unit tests covering instantiation, update, retrieve (threshold, ordering, errors), count, load/save no-ops, and the lazy import error path. All tests use mocked glide_sync.
  • uv.lock — lock file updated for valkey-glide-sync 2.4.1.

Tests

Unit tests in tests/test_valkey_memory.py cover:

  • Index creation (happy path, already-exists, missing Search module)
  • update() hash storage, float32 encoding, TTL expire calls, empty-input short circuit
  • retrieve() result parsing, similarity threshold filtering, descending sort, empty query, search errors
  • count_memories() via ft.info
  • _get_glide_sync() ImportError when the package is missing

Run with pytest tests/test_valkey_memory.py -v.

Signed-off-by: Edward Liang <edward.liang@improving.com>
@edlng edlng requested a review from atao2004 June 5, 2026 18:11
Signed-off-by: Edward Liang <edward.liang@improving.com>

@atao2004 atao2004 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey the code looks pretty good I didn't find any bugs. The implementation follows the same patterns as Mem0Memory and GLIDE API usage seems correct.

Just two things; wondering if we need to filter by agent_role as per the spec and to check if it would be helpful to use tls.

Comment thread runtime/node/agent/memory/valkey_memory.py Outdated
Comment thread runtime/node/agent/memory/valkey_memory.py Outdated
Signed-off-by: Edward Liang <edward.liang@improving.com>
@atao2004

atao2004 commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

LGTM!

@edlng edlng merged commit 25e82ae into add-valkey Jun 5, 2026
@edlng edlng deleted the add-valkey-memory branch June 5, 2026 22:59
atao2004 added a commit that referenced this pull request Jun 8, 2026
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.

2 participants