dify - ✅(Solved) Fix Add Valkey as a Vector Store Backend [2 pull requests, 1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langgenius/dify#35229Fetched 2026-04-15 06:45:30
View on GitHub
Comments
1
Participants
1
Timeline
4
Reactions
1
Author
Participants
Assignees
Timeline (top)
labeled ×2assigned ×1commented ×1

PR fix notes

PR #35337: feat: add Valkey as a vector store backend

Description (problem / solution / changelog)

Fixes #35229

Summary

Adds Valkey as a supported vector database backend for knowledge base embeddings and retrieval in Dify, using valkey-glide (the official Valkey Python client) and the valkey-search module for vector similarity search.

What's included:

  • VALKEY added to the VectorType enum
  • ValkeyVector implementing the full BaseVector interface (create, add, search, delete)
  • ValkeyVectorFactory registered via entry point in pyproject.toml
  • ValkeyConfig Pydantic settings with env vars: VALKEY_HOST, VALKEY_PORT, VALKEY_PASSWORD, VALKEY_DB, VALKEY_USE_SSL, VALKEY_DISTANCE_METRIC
  • Valkey service in docker-compose.yaml using valkey/valkey-bundle:9.1.0-rc1 (includes valkey-search module 1.2.0)
  • CI integration: Valkey added to both vdb-tests.yml (smoke) and vdb-tests-full.yml (weekly)
  • 35 unit tests (pure logic, no mocks) + 31 integration tests (live Valkey)

Key design decisions:

  • Uses the typed ft.create / ft.search glide API where available, client.hset / client.exists / client.delete for CRUD
  • HNSW vector index with configurable distance metric (COSINE, L2, IP)
  • Dimensions auto-detected from first embedding
  • Distributed locking via Dify's existing Redis client (ext_redis) for index creation — same pattern as Qdrant backend
  • Cosine distance conversion follows the valkey-search spec: similarity = 1 - distance/2 (range [0, 2])

Dependencies:

  • valkey-glide>=1.3.0 — official async Valkey client
  • Valkey server with valkey-search module >= 1.2.0

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly: https://github.com/langgenius/dify-docs/pull/750
  • I ran make lint && make type-check (backend) and cd web && pnpm exec vp staged (frontend) to appease the lint gods

Changed files

  • .github/workflows/vdb-tests-full.yml (modified, +1/-0)
  • .github/workflows/vdb-tests.yml (modified, +2/-0)
  • api/.env.example (modified, +9/-1)
  • api/configs/middleware/__init__.py (modified, +2/-0)
  • api/configs/middleware/vdb/valkey_config.py (added, +36/-0)
  • api/core/rag/datasource/vdb/vector_type.py (modified, +1/-0)
  • api/providers/vdb/vdb-valkey/pyproject.toml (added, +14/-0)
  • api/providers/vdb/vdb-valkey/src/dify_vdb_valkey/__init__.py (added, +1/-0)
  • api/providers/vdb/vdb-valkey/src/dify_vdb_valkey/valkey_vector.py (added, +630/-0)
  • api/providers/vdb/vdb-valkey/tests/integration_tests/test_valkey.py (added, +416/-0)
  • api/providers/vdb/vdb-valkey/tests/unit_tests/test_valkey_vector.py (added, +246/-0)
  • api/pyproject.toml (modified, +3/-0)
  • api/tests/unit_tests/core/rag/datasource/vdb/test_vector_factory.py (modified, +1/-0)
  • api/uv.lock (modified, +34/-0)
  • docker/.env.example (modified, +9/-1)
  • docker/docker-compose.yaml (modified, +18/-0)
RAW_BUFFERClick to expand / collapse

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • Please do not modify this template :) and fill in all the required fields.

1. Is this request related to a challenge you're experiencing? Tell me about your story.

Feature Description

Add Valkey as a supported vector database backend for knowledge base embeddings and retrieval in Dify. This would add a new VectorType.VALKEY option alongside the existing supported vector stores, using valkey-glide (the official Valkey Python client) to provide vector similarity search through Valkey's built-in valkey-search module.

Problem

Dify currently uses Redis extensively for caching and as a Celery message broker, but has no Redis or Valkey option for vector storage. Teams already running Valkey infrastructure for Dify's cache layer have to deploy a separate vector database (Weaviate, Qdrant, Milvus, etc.) for knowledge base embeddings. This adds operational complexity and cost when their existing Valkey instance could handle both.

Valkey has become increasingly common in production since the Redis license change — it's a Linux Foundation project with transparent open-source governance, and major cloud providers offer managed Valkey services.

Proposed Solution

Add a Valkey vector store implementation following Dify's existing factory pattern:

  1. Add VALKEY to the VectorType enum in api/core/rag/datasource/vdb/vector_type.py
  2. Create api/core/rag/datasource/vdb/valkey/valkey_vector.py implementing the vector store interface
  3. Add case handling in vector_factory.py
  4. Add Valkey configuration to middleware settings and .env.example

The implementation would use valkey-glide with Valkey's native search commands for vector indexing and retrieval.

Value

  • Unified infrastructure: Teams already running Valkey for Dify's cache/broker can reuse the same instance for vector storage, reducing operational complexity
  • Performance: Valkey's valkey-search module delivers single-digit millisecond latency with 99%+ recall for vector search
  • Scaling: Linear scaling with cluster mode support
  • Open-source governance: Linux Foundation project with community-driven development
  • Cloud support: Managed services from major cloud providers
  • Cost reduction: Eliminates the need for a separate vector database deployment

2. Additional context or comments

Alternatives Considered

  • Adding Redis Stack as a vector store: Would require RediSearch module (part of Redis Stack). While Redis and Valkey are mostly protocol-compatible for core operations, their search modules are not — code written for RediSearch does not work with Valkey's valkey-search module.
  • Using an existing supported vector store: Works, but requires teams to deploy and maintain a separate database when their Valkey instance could serve both purposes.

3. Can you help us with this feature?

  • I am interested in contributing to this feature.

extent analysis

TL;DR

To add Valkey as a supported vector database backend, implement the proposed solution by adding a Valkey vector store implementation following Dify's existing factory pattern.

Guidance

  • Add VALKEY to the VectorType enum in api/core/rag/datasource/vdb/vector_type.py to enable Valkey as a vector store option.
  • Create api/core/rag/datasource/vdb/valkey/valkey_vector.py to implement the vector store interface using valkey-glide and Valkey's native search commands.
  • Update vector_factory.py to handle the new Valkey case and add Valkey configuration to middleware settings and .env.example.
  • Verify the implementation by testing vector indexing and retrieval using Valkey's valkey-search module.

Example

# api/core/rag/datasource/vdb/vector_type.py
from enum import Enum

class VectorType(Enum):
    # ...
    VALKEY = 'valkey'

Notes

The implementation should follow Dify's existing factory pattern and use valkey-glide with Valkey's native search commands for vector indexing and retrieval.

Recommendation

Apply the proposed workaround by implementing the Valkey vector store implementation, as it provides a unified infrastructure solution with performance, scaling, and cost reduction benefits.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING