feat: add Valkey as RAG vector store backend#2063
Open
daric93 wants to merge 4 commits into
Open
Conversation
Integrate Valkey Search module as a RAG vector store backend using the existing ConfigBasedFactory pattern. - Add ValkeyStoreConfig, ValkeyIndexConfig, ValkeyRetrieverConfig schemas - Implement ValkeyVectorStore (BasePydanticVectorStore) using valkey-glide - Implement ValkeyRetriever extending RAGRetriever - Register Valkey in RAGIndexFactory and RetrieverFactory - Add valkey-glide>=2.1.0,<3.0.0 to rag extras in setup.py - Add Valkey configuration example to config2.example.yaml - Unit + integration tests (54 passing) against live Valkey Requires Valkey with Search module (valkey-bundle:9.1). Jira: AEA-506 Signed-off-by: Daria Korenieva <daric2612@gmail.com>
- Rewrite ValkeyVectorStore on the synchronous glide_sync client, removing the persistent-loop / run_async threading bridge to match the other RAG backends (FAISS/Chroma/ES) and eliminate the deadlock risk - Use native glide methods (delete/ping/scan, glide_json.set) instead of custom_command; batch inserts now use an atomic glide Batch (one round-trip) - Use ft.list() for index existence checks instead of error-string matching - Fix delete(ref_doc_id) to remove all chunks sharing a source doc id - Add embedding-dimension validation, FT.SEARCH response-shape guards, and warning logs on metadata/score parse fallback - Redact password in repr (store + ValkeyStoreConfig); warn when password is set without TLS - Type distance_metric/vector_algorithm as Literal so bad values fail at config - Retriever uses only public store methods and prefers aget_query_embedding - Remove unused escape helpers; add vector_algorithm to config example; add valkey-glide-sync dependency; annotate _create_valkey_retriever return - Rewrite unit + integration tests for the sync client (31 unit, 15 integration)
Move the seven in-method 'from glide_sync import ...' statements in valkey.py into a single top-level import block, matching how the RAG factories import chromadb/faiss at module top. Optionality is already enforced at the factory boundary (ValkeyVectorStore is lazily imported inside _create_valkey), so per-method imports added no real isolation. Update unit tests to patch glide_sync symbols on the valkey module namespace (patch.multiple) instead of sys.modules, since the names are now bound at import time. Tests: 31 unit, 15 integration, 16 factory (62) pass; black/isort/ruff clean. Signed-off-by: Daria Korenieva <daric2612@gmail.com>
…s The embedding tests assigned a PropertyMock directly to the shared singleton config.llm.proxy without mocker.patch, so pytest-mock never restored it. The leaked PropertyMock then propagated to the global config and caused the autouse llm_mock fixture to pass an invalid proxy to httpx, breaking unrelated tests (e.g. the Valkey RAG suite) with 'Proxy protocol must be either http, https, socks5, or socks5h'. Use mocker.patch.object so the original proxy value is restored on teardown. Signed-off-by: Daria Korenieva <daric2612@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2062
Summary
Adds Valkey (via the Valkey Search module) as a RAG vector store backend in MetaGPT, following the existing
ConfigBasedFactorypattern used by FAISS, Chroma, and Elasticsearch.Changes
metagpt/rag/schema.py):ValkeyStoreConfig,ValkeyIndexConfig,ValkeyRetrieverConfigmetagpt/rag/vector_stores/valkey.py):ValkeyVectorStoreimplementing llama-indexBasePydanticVectorStore, backed byvalkey-glideFT.CREATE / FT.SEARCH (HNSW + KNN)metagpt/rag/retrievers/valkey_retriever.py):ValkeyRetrieverextendingRAGRetrieverRAGIndexFactoryandRetrieverFactory(lazy imports sovalkey-glidestays optional)setup.py):valkey-glide>=2.1.0,<3.0.0added to theragextraconfig/config2.example.yaml): commented Valkey sectionDesign notes
VectorField, COSINE distance, FLOAT32. FLAT algorithm also supported.client_name="metagpt_rag_client"on all connections.asyncio.gather(_BATCH_SIZE=100); raises on partial failure._MAX_SCAN_ITERATIONS;drop_index()always cleans orphaned keys.Testing
valkey/valkey-bundle:9.1, Search module) onlocalhost:6379— not skipped.black,isort,ruffall clean.How to test manually
Configuration required
New optional
valkeysection inconfig2.yaml(seeconfig/config2.example.yaml):hostlocalhostport6379passwordNoneuse_tlsfalserequest_timeout5000index_namemetagpt_ragprefixmetagpt:rag:vector_dimensions1536distance_metricCOSINEvector_algorithmHNSWRequirements
Requires a Valkey deployment with the Search module (e.g.
valkey/valkey-bundle:9.1). Purely additive — no changes to existing backends.