From 5bc62d32dca2c44efdf4c9e2a907c89f07b41118 Mon Sep 17 00:00:00 2001 From: "shuwen.wu" Date: Wed, 2 Sep 2026 17:58:02 +0800 Subject: [PATCH] fix: ValkeySemanticCache import compatibility with redis-py >= 5 Fixes #39180 - ValkeySemanticCache crashes at import with redis-py >= 5 due to stale camelCase import of redis.commands.search.indexDefinition. redis-py >= 5 uses snake_case module name (index_definition), while redis-py 4.x uses camelCase (indexDefinition). Add try/except to support both versions. --- litellm/caching/valkey_semantic_cache.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/litellm/caching/valkey_semantic_cache.py b/litellm/caching/valkey_semantic_cache.py index 58b76d98d6d..4f6e1b9564f 100644 --- a/litellm/caching/valkey_semantic_cache.py +++ b/litellm/caching/valkey_semantic_cache.py @@ -24,7 +24,10 @@ 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: # redis-py >= 5 (module renamed to snake_case) + from redis.commands.search.index_definition import IndexDefinition, IndexType +except ModuleNotFoundError: # redis-py 4.x (last version with camelCase name) + from redis.commands.search.indexDefinition import IndexDefinition, IndexType from redis.commands.search.query import Query from litellm._logging import print_verbose