Skip to content

Conversation

@daric93
Copy link
Owner

@daric93 daric93 commented Nov 6, 2025

This PR introduces Valkey integration for the Redis-based vector store in GPTCache. Key changes include:

Valkey compatibility:

  • Detects Valkey vs Redis behavior for FT.SEARCH.
  • Handles cases where Valkey does not support SORTBY (current module limitation).

Conditional SORTBY logic:

  • Adds runtime capability check before appending .sort_by("score") to queries.
  • Falls back gracefully when SORTBY is unsupported (avoids query errors).

No breaking changes:

  • Existing Redis functionality remains unchanged.
  • Valkey support is transparent to callers.

@daric93 daric93 self-assigned this Nov 6, 2025
_never_supports_sortby,
raising=True,
)

Choose a reason for hiding this comment

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

Suggestion: Add assertion/ test for sorting: scores = [extract_score(item) for item in res]; assert is_nondecreasing(scores), f"KNN results must be sorted: {scores}"

Copy link
Owner Author

Choose a reason for hiding this comment

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

added assertion


_sortby_supported: bool | None = None

def _check_sortby_support(self, index_name: str, sort_field: str) -> bool:

Choose a reason for hiding this comment

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

Update docstring: Add "NOTE: Valkey KNN results are ALWAYS sorted by distance. 'The first name/value pair is for the distance computed' - Ref: https://github.com/valkey-io/valkey-search/blob/main/COMMANDS.md"

Copy link
Owner Author

Choose a reason for hiding this comment

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

added

self._sortby_supported = False
else:
self._sortby_supported = True
return self._sortby_supported

Choose a reason for hiding this comment

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

Suggestion: verify it's Valkey before skipping SORTBY, as it is uncertain if there might be other cases (not Valkey) where SORT BY is not supported and no default sorting is guaranteed.

except ResponseError as e:
    if "SORTBY" in str(e):
        try:
            info = self._client.info("server")
            is_valkey = info.get("server_name") == "valkey" or "valkey_version" in info
            self._sortby_supported = not is_valkey
        except Exception:
            self._sortby_supported = False
    else:
        self._sortby_supported = True
    return self._sortby_supported

Copy link
Owner Author

Choose a reason for hiding this comment

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

added verification

docs/index.rst Outdated
* [x] Support `Chroma <https://github.com/chroma-core/chroma>`_\ , the AI-native open-source embedding database.
* [x] Support `DocArray <https://github.com/docarray/docarray>`_\ , DocArray is a library for representing, sending and storing multi-modal data, perfect for Machine Learning applications.
* [x] Support `Redis <https://redis.io/>`_.
* [x] Support `ValkeySearch <https://github.com/valkey-io/valkey-search/>`_\ , provided as a Valkey module, is a high-performance Vector Similarity Search engine optimized for AI-driven workloads.

Choose a reason for hiding this comment

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

Instead of ValkeySearch - suggesting to add Valkey (with valkey-search)

Copy link
Owner Author

Choose a reason for hiding this comment

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

changed

Copy link

@jbrinkman jbrinkman left a comment

Choose a reason for hiding this comment

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

LGTM with @alexey-temnikov suggested changes

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.

4 participants