google / google/adk-python-community
feat: Add ValkeyMemoryService with vector similarity search (Valkey Search module)
- 主要语言
- Python
- 星标
- 182
- 派生
- 75
- PR 合并指标
- 30 天内没有已合并 PR
描述
## Summary
Add a `ValkeyMemoryService` implementation for the ADK community memory module, backed by Valkey using the Valkey Search module for vector similarity search (HNSW). This would use the `valkey-glide` client library and provide functionality analogous to `VertexAiRagMemoryService` for developers with Valkey infrastructure.
## Motivation
Currently, the community memory module has limited backend options. Valkey (the open-source fork of Redis) with the Search module provides a high-performance, self-hosted vector database option that many teams already run in production. Adding a Valkey-backed memory service would expand the ecosystem for developers who prefer or already use Valkey infrastructure.
## Proposed Implementation
- `ValkeyMemoryService` class implementing `BaseMemoryService` interface
- `ValkeyMemoryServiceConfig` (Pydantic) with configurable: `similarity_top_k`, `vector_distance_threshold`, `embedding_dimensions`, `key_prefix`, `index_name`, `distance_metric` (COSINE/L2/IP), `ttl_seconds`
- Accepts a configurable async embedding function (users bring their own embedder — OpenAI, Gemini, sentence-transformers, etc.)
- Stores memories as Valkey Hash keys with FLOAT32 vector embeddings
- Uses `FT.CREATE` with VECTOR field (HNSW algorithm) + TAG fields for `app_name`/`user_id` scoped queries
- Uses `FT.SEARCH` with KNN for vector similarity retrieval, pre-filtered by TAG
- Implements both `add_session_to_memory` and `add_events_to_memory`
- Uses `Batch` pipelining for efficient ingestion (1 round trip regardless of event count)
- `asyncio.Lock` with double-check locking for thread-safe index creation
- Configurable distance threshold, distance metric, TTL
## Dependencies
- `valkey-glide >= 2.4.0` (as optional dependency under `[valkey]` extra)
- Valkey server with the Search module loaded (e.g., `valkey/valkey-bundle` image)
## Testing Plan
- Unit tests (mocked client): cover all public methods, edge cases, error conditions
- Integration tests: run against live Valkey 9.1 (`valkey/valkey-bundle` image) covering vector similarity search, user/app isolation, top-k limits, distance threshold filtering, metadata preservation, index idempotency
贡献指南
调研方向
首先阅读现有的 BaseMemoryService 接口以及对应的 VertexAiRagMemoryService 实现。审查拟议的 ValkeyMemoryServiceConfig、公共方法和测试计划,然后验证 issue 中描述的模拟客户端和实时 Valkey 集成案例。完成的标准是该服务支持作用域限定的向量检索、数据摄取、配置以及列出的边界情况。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend, databases
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100