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.
This commit is contained in:
shuwen.wu 2026-09-02 17:58:02 +08:00
parent 31ca4ddf32
commit 5bc62d32dc

View file

@ -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