{"record":{"id":"64551e87194dbfe1","repo":"BerriAI/litellm","slug":"similarity-threshold-must-be-provided-passed-none-64551e","errorCode":null,"errorMessage":"similarity_threshold must be provided, passed None","messagePattern":"similarity_threshold must be provided, passed None","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/caching/redis_semantic_cache.py","lineNumber":79,"sourceCode":"            similarity_threshold: Threshold for semantic similarity (0.0 to 1.0)\n                where 1.0 requires exact matches and 0.0 accepts any match\n            embedding_model: Model to use for generating embeddings\n            index_name: Name for the Redis index\n            ttl: Default time-to-live for cache entries in seconds\n            **kwargs: Additional arguments passed to the Redis client\n\n        Raises:\n            Exception: If similarity_threshold is not provided or required Redis\n                connection information is missing\n        \"\"\"\n        if index_name is None:\n            index_name = self.DEFAULT_REDIS_INDEX_NAME\n\n        print_verbose(f\"Redis semantic-cache initializing index - {index_name}\")\n\n        # Validate similarity threshold\n        if similarity_threshold is None:\n            raise ValueError(\"similarity_threshold must be provided, passed None\")\n\n        # Store configuration\n        self.similarity_threshold = similarity_threshold\n\n        # Convert similarity threshold [0,1] to distance threshold [0,2]\n        # For cosine distance: 0 = most similar, 2 = least similar\n        # While similarity: 1 = most similar, 0 = least similar\n        self.distance_threshold = 1 - similarity_threshold\n        self.embedding_model = embedding_model\n\n        # Set up Redis connection\n        if redis_url is None:\n            try:\n                # Attempt to use provided parameters or fallback to environment variables\n                host = host or os.environ[\"REDIS_HOST\"]\n                port = port or os.environ[\"REDIS_PORT\"]\n                password = password or os.environ[\"REDIS_PASSWORD\"]\n            except KeyError as e:","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/caching/redis_semantic_cache.py#L61-L97","documentation":"RedisSemanticCache.__init__ requires an explicit similarity_threshold; None is rejected with ValueError because the threshold defines when a cached response counts as a semantically equivalent match, and a wrong default would silently return bad cache hits. Unlike the Qdrant cache this is a ValueError, but it behaves the same: raised at construction time.","triggerScenarios":"Instantiating litellm.caching.redis_semantic_cache.RedisSemanticCache without similarity_threshold (or with None); configuring litellm proxy caching with type='redis-semantic' and omitting the threshold.","commonSituations":"Adopting the Redis semantic cache from the plain RedisCache and assuming defaults; config YAML written from partial documentation.","solutions":["Pass similarity_threshold explicitly, e.g. RedisSemanticCache(host=..., port=..., password=..., similarity_threshold=0.8)","Add similarity_threshold to the redis-semantic cache block in your litellm proxy config"],"exampleFix":"# before\ncache = RedisSemanticCache(host=h, port=p, password=pw)\n\n# after\ncache = RedisSemanticCache(host=h, port=p, password=pw, similarity_threshold=0.8)","handlingStrategy":"validation","validationCode":"if cfg.get('similarity_threshold') is None:\n    raise ValueError('redis semantic cache requires similarity_threshold (e.g. 0.8)')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Share one validated config-builder function for all semantic caches so the threshold can't be omitted","Add schema validation (pydantic) over litellm proxy YAML before deploy"],"tags":["redis","semantic-cache","configuration","validation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}