From a36c652b417dc963d29e9ea52b95e64ca0b2a21e Mon Sep 17 00:00:00 2001 From: Anish Gurjar <50738829+anishgurjar@users.noreply.github.com> Date: Mon, 28 Sep 2026 11:37:03 -0400 Subject: [PATCH 1/2] Fix ValkeySemanticCache import for redis-py >= 5 --- litellm/caching/valkey_semantic_cache.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/litellm/caching/valkey_semantic_cache.py b/litellm/caching/valkey_semantic_cache.py index 58b76d98d6d..a6552a97ce8 100644 --- a/litellm/caching/valkey_semantic_cache.py +++ b/litellm/caching/valkey_semantic_cache.py @@ -24,7 +24,11 @@ from typing import Any, Final from redis import Redis from redis.asyncio import Redis as AsyncRedis from redis.commands.search.field import TagField, VectorField -from redis.commands.search.indexDefinition import IndexDefinition, IndexType + +try: + from redis.commands.search.index_definition import IndexDefinition, IndexType +except ModuleNotFoundError: + from redis.commands.search.indexDefinition import IndexDefinition, IndexType from redis.commands.search.query import Query from litellm._logging import print_verbose From 5e9eab81428fd4f2f59eb9fd6ac164fed5da9a9c Mon Sep 17 00:00:00 2001 From: Anish Gurjar <50738829+anishgurjar@users.noreply.github.com> Date: Mon, 28 Sep 2026 11:37:51 -0400 Subject: [PATCH 2/2] Add regression test for Valkey index definition import --- tests/unit/caching/test_valkey_semantic_cache.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/unit/caching/test_valkey_semantic_cache.py b/tests/unit/caching/test_valkey_semantic_cache.py index 749658784ac..2e7f79e5a9c 100644 --- a/tests/unit/caching/test_valkey_semantic_cache.py +++ b/tests/unit/caching/test_valkey_semantic_cache.py @@ -99,6 +99,11 @@ def test_build_valkey_url_uses_rediss_scheme_when_ssl(monkeypatch): ).startswith("redis://") +def test_index_definition_uses_supported_redis_search_types(): + definition = _make_cache()._index_definition() + assert definition.args[:5] == ["ON", "HASH", "PREFIX", 1, "test_index:"] + + def test_init_requires_similarity_threshold(): with pytest.raises(ValueError, match="similarity_threshold must be provided"): ValkeySemanticCache(sync_client=MagicMock(), async_client=AsyncMock())