-
Notifications
You must be signed in to change notification settings - Fork 567
Description
What would you like to be added?
Enabling Valkey support in GPTCache as an alternative to Redis for vector store functionality.
Since Valkey is a drop-in replacement for Redis and shares the same protocol, most of the existing Redis-related code in GPTCache works seamlessly with Valkey.
However, there is a compatibility issue:
Valkey currently does not support SORTBY in its search queries. This limitation is tracked in valkey-io/valkey-search#48.
Problem
GPTCache’s Redis vector store implementation uses SORTBY in search queries. When running GPTCache with Valkey, this results in query failures due to the unsupported SORTBY clause.
Important Note
Valkey automatically sorts KNN results by distance, which is the same behavior GPTCache achieves using SORTBY in Redis. Therefore, omitting SORTBY in Valkey does not affect result correctness—the returned results remain properly ordered by similarity.
Proposed Solution
Introduce a conditional check before executing the search query. If the backend is Valkey and SORTBY is not supported, the query is adjusted to omit the SORTBY clause, allowing the search to proceed successfully.
This workaround enables GPTCache to function with Valkey while maintaining compatibility with Redis.
Valkey does not currently expose feature capabilities via commands like INFO, so there's no reliable way to check for SORTBY support programmatically. As a result, using exception handling is the most practical approach to detect and work around unsupported features.
Enabling SORTBY support in Valkey itself may take some time and will only be available in future versions of Valkey. Until then, the proposed workaround ensures GPTCache remains functional and compatible.
Why is this needed?
Valkey is a fully open-source alternative to Redis that provides the same protocol and core functionality, including vector search capabilities. Supporting Valkey in GPTCache allows users to adopt a truly open-source stack without relying on Redis's licensing model.
Proposed enhancement improves backend flexibility and broadens GPTCache’s compatibility with open-source infrastructure.