Skip to content

adds Valkey Storage Implementation#5603

Closed
MatthiasHowellYopp wants to merge 1 commit intocrewAIInc:mainfrom
MatthiasHowellYopp:feat/valkey-storage
Closed

adds Valkey Storage Implementation#5603
MatthiasHowellYopp wants to merge 1 commit intocrewAIInc:mainfrom
MatthiasHowellYopp:feat/valkey-storage

Conversation

@MatthiasHowellYopp
Copy link
Copy Markdown
Contributor

Adds Valkey as a storage backend for CrewAI's unified memory system, using the valkey-glide client. Valkey is a high-performance, Redis-compatible key-value store that provides a distributed, production-ready alternative to the existing LanceDB and Qdrant storage options.

What's included
ValkeyStorage (valkey_storage.py) — full StorageBackend implementation:

CRUD operations (save, get, update, delete) with both sync and async APIs
Server-side vector search via Valkey Search module (FT.SEARCH with KNN)
Scope-based record organization with hierarchical scope queries
Category indexing and filtering
Metadata filtering with AND logic
Pagination support (limit/offset) for list_records
Scope introspection (get_scope_info, list_scopes, list_categories, count)
Bulk delete with scope, category, metadata, and age-based filters
Connection retry with exponential backoff for transient errors
Lazy client initialization and async context manager support
reset for clearing all or scoped records
ValkeyCache (valkey_cache.py) — lightweight cache interface:

get/set/delete/exists with optional TTL
JSON serialization for complex values
Connection timeout handling
Used by A2A agent card caching and file upload caching as an alternative to Redis
Integration points:

unified_memory.py — wired as a storage backend option
encoding_flow.py — encoding flow support for Valkey storage
memory_tools.py — memory tool descriptions updated with clearer parameter docs
upload_cache.py — added ValkeyCache as a cache backend option (alongside memory/Redis)
agent_card.py / task.py — added VALKEY_URL environment variable support for aiocache configuration, with priority over REDIS_URL
Optional dependency:

Added valkey = ["valkey-glide>=1.3.0"] to [project.optional-dependencies] in
pyproject.toml
Install with pip install crewai[valkey]
Tests
~5,300 lines of tests across 5 test files covering:

Core CRUD and index operations (test_valkey_storage.py)
Vector search with filters, scoring, pagination (test_valkey_storage_search.py)
Scope operations, listing, categories, count, reset (test_valkey_storage_scope.py)
Error handling, retry, serialization/deserialization (test_valkey_storage_errors.py)
Cache operations with TTL (test_valkey_cache.py)
All tests use mocked Valkey clients — no running Valkey instance required.

fixes #5578

@MatthiasHowellYopp MatthiasHowellYopp force-pushed the feat/valkey-storage branch 10 times, most recently from 4fbf22f to b8c5d27 Compare April 28, 2026 18:37
Comment thread lib/crewai/src/crewai/memory/storage/valkey_cache.py Fixed
Comment thread lib/crewai/src/crewai/memory/storage/valkey_cache.py Fixed
@MatthiasHowellYopp MatthiasHowellYopp force-pushed the feat/valkey-storage branch 3 times, most recently from 5b1f60b to 9b12c62 Compare April 29, 2026 13:01
Comment thread lib/crewai/src/crewai/memory/storage/valkey_cache.py Fixed
Comment thread lib/crewai/src/crewai/memory/storage/valkey_cache.py Fixed
Comment thread lib/crewai/src/crewai/memory/storage/valkey_cache.py Fixed
Comment thread lib/crewai/src/crewai/memory/storage/valkey_cache.py Fixed
Comment thread lib/crewai/src/crewai/memory/storage/valkey_cache.py Fixed
Comment thread lib/crewai/src/crewai/memory/storage/valkey_cache.py Fixed
Comment thread lib/crewai/src/crewai/memory/storage/valkey_cache.py Fixed
Comment thread lib/crewai/src/crewai/memory/storage/valkey_cache.py Fixed
Comment thread lib/crewai/src/crewai/memory/storage/valkey_cache.py Fixed
Comment thread lib/crewai/src/crewai/memory/storage/valkey_cache.py Fixed
@MatthiasHowellYopp MatthiasHowellYopp force-pushed the feat/valkey-storage branch 2 times, most recently from bbcfde3 to 7bf8324 Compare April 29, 2026 13:55
@MatthiasHowellYopp
Copy link
Copy Markdown
Contributor Author

@greysonlalonde Hoping someone can review this, thanks.

@MatthiasHowellYopp MatthiasHowellYopp force-pushed the feat/valkey-storage branch 5 times, most recently from 2e55991 to c282ab2 Compare April 30, 2026 20:06
Copy link
Copy Markdown

@Jonathan-Improving Jonathan-Improving left a comment

Choose a reason for hiding this comment

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

Consolidated PR Review — Valkey Storage Implementation

Reviewers: GLIDE API validation, Python code quality / DRY, Security (OWASP methodology)
19 files, +9276 / -904 lines, ~5300 lines of tests

See inline comments for specific findings at the relevant lines.

  • 🔴 5 must-fix: FT.SEARCH query injection via => token, wrong import paths (ImportError), key construction injection, TLS cert params are silent no-ops, credentials set post-construction
  • 🟡 7 suggestions: Use ft.list() not ft.info() for index check, N+1 query patterns, duplicated client init, duplicated category parsing (4×), duplicated bytes decoding (5×), dead _retry_operation, pagination fetches all records first
  • 🟢 7 low items: Positional GLIDE API args, scan cursor type, f-strings in logging, deprecated datetime.utcnow(), TOCTOU in index creation, no batching for bulk saves, _run_async returns Any

✅ Security Assessment

  • 1 HIGH: FT.SEARCH => injection via LLM-inferred scope/category values
  • 2 MEDIUM: Key construction injection, TLS cert silent no-ops

✅ GLIDE API

  • Correct ft.create(client, ...) / ft.search(client, ...) module-level pattern ✅
  • Correct KNN query syntax with filter expressions ✅
  • Correct binary embedding handling with numpy float32 ✅
  • Import paths need fixing (internal glide.async_commands vs stable glide_shared) ❌

✅ What's Done Well

  • Comprehensive 5300-line test suite covering CRUD, search, scopes, errors, cache
  • Correct cosine distance→similarity conversion
  • Lazy client init, connection timeouts, retry logic design
  • Thread-safe sync/async bridge with persistent background event loop
  • Optional peer dependency — no impact on non-Valkey users
  • Proper integration into unified memory, encoding flow, A2A cache
  • Good documentation with docstrings and forward-compat notes

Comment thread lib/crewai/src/crewai/memory/storage/valkey_storage.py
Comment thread lib/crewai/src/crewai/memory/storage/valkey_storage.py Outdated
Comment thread lib/crewai/src/crewai/memory/storage/valkey_storage.py
Comment thread lib/crewai/src/crewai/memory/storage/valkey_storage.py
Comment thread lib/crewai/src/crewai/memory/storage/valkey_cache.py Outdated
Comment thread lib/crewai/src/crewai/memory/storage/valkey_storage.py Outdated
Comment thread lib/crewai/src/crewai/memory/storage/valkey_storage.py Outdated
@MatthiasHowellYopp MatthiasHowellYopp force-pushed the feat/valkey-storage branch 2 times, most recently from 148515c to 3a5ecce Compare May 1, 2026 20:37
@greysonlalonde
Copy link
Copy Markdown
Contributor

Hey @MatthiasHowellYopp , this is nice! For digestibility, can you split this into multiple PRs? ~10k lines is too large for us to review

@MatthiasHowellYopp
Copy link
Copy Markdown
Contributor Author

@greysonlalonde I've broken it down into 4 prs:
#1 #5700
#2 #5701
#3 #5702
#4 #5703

Hoping that works, thanks.

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.

[FEATURE] Add Valkey as a storage backend for the unified memory system

4 participants