The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Clean up Redis semantic cache isolation fallback
user9f1feaadeb97
diff --git a/litellm/caching/redis_semantic_cache.py b/litellm/caching/redis_semantic_cache.pyindex 27538530bca..4d685c6a872 100644--- a/litellm/caching/redis_semantic_cache.py+++ b/litellm/caching/redis_semantic_cache.py@@ -129,7 +129,11 @@ class RedisSemanticCache(BaseCache):cache_vectorizer: Any,) -> Any:def _is_schema_mismatch(exc: ValueError) -> bool:- return "schema does not match" in str(exc)+ error_message = str(exc).lower()+ return any(+ phrase in error_message+ for phrase in ("schema does not match", "index schema")+ )try:return semantic_cache_cls(@@ -284,9 +288,7 @@ class RedisSemanticCache(BaseCache):ttl = self._get_ttl(**kwargs)if ttl is not None:store_kwargs["ttl"] = int(ttl)- self.llmcache.store(prompt, value_str, **store_kwargs)- else:- self.llmcache.store(prompt, value_str, **store_kwargs)+ self.llmcache.store(prompt, value_str, **store_kwargs)except Exception as e:print_verbose(f"Error setting {value_str or value} in the Redis semantic cache: {str(e)}"@@ -439,17 +441,11 @@ class RedisSemanticCache(BaseCache):ttl = self._get_ttl(**kwargs)if ttl is not None:store_kwargs["ttl"] = ttl- await self.llmcache.astore(- prompt,- value_str,- **store_kwargs,- )- else:- await self.llmcache.astore(- prompt,- value_str,- **store_kwargs,- )+ await self.llmcache.astore(+ prompt,+ value_str,+ **store_kwargs,+ )except Exception as e:print_verbose(f"Error in async_set_cache: {str(e)}")@@ -489,9 +485,7 @@ class RedisSemanticCache(BaseCache):# handle results / cache hitif not results:- kwargs.setdefault("metadata", {})[- "semantic-similarity"- ] = 0.0 # TODO why here but not above??+ kwargs.setdefault("metadata", {})["semantic-similarity"] = 0.0return Nonecache_hit = results[0]diff --git a/tests/test_litellm/caching/test_redis_semantic_cache.py b/tests/test_litellm/caching/test_redis_semantic_cache.pyindex 02b06bed62d..495c72a3803 100644--- a/tests/test_litellm/caching/test_redis_semantic_cache.py+++ b/tests/test_litellm/caching/test_redis_semantic_cache.py@@ -195,7 +195,7 @@ def test_redis_semantic_cache_uses_isolated_index_for_old_schema(monkeypatch):fallback_cache_mock = MagicMock()semantic_cache_mock = MagicMock(side_effect=[- ValueError("Existing index schema does not match"),+ ValueError("stored index schema differs from requested fields"),fallback_cache_mock,])