{"record":{"id":"87ed6910e823f74f","repo":"BerriAI/litellm","slug":"similarity-threshold-must-be-provided-passed-none-87ed69","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/valkey_semantic_cache.py","lineNumber":67,"sourceCode":"    DISTANCE_FIELD_NAME: str = \"vector_distance\"\n\n    def __init__(\n        self,\n        host: str | None = None,\n        port: str | None = None,\n        password: str | None = None,\n        redis_url: str | None = None,\n        similarity_threshold: float | None = None,\n        embedding_model: str = \"text-embedding-ada-002\",\n        index_name: str | None = None,\n        ssl: bool = False,\n        startup_nodes: list | None = None,\n        sync_client: Redis | None = None,\n        async_client: AsyncRedis | None = None,\n        **kwargs: Any,\n    ):\n        if similarity_threshold is None:\n            raise ValueError(\"similarity_threshold must be provided, passed None\")\n\n        if startup_nodes:\n            raise ValueError(\n                \"valkey-semantic does not support cluster-mode-enabled (multi-shard) \"\n                \"endpoints. The async cluster client cannot route the FT.* search \"\n                \"commands reliably. Point it at a cluster-mode-disabled endpoint \"\n                \"instead (a primary with replicas is fine; only horizontal sharding \"\n                \"is unsupported), or pass a single redis_url. On AWS, vector search \"\n                \"needs ElastiCache for Valkey 8.2+ on a node-based cluster.\"\n            )\n\n        self.similarity_threshold = similarity_threshold\n        self.embedding_model = embedding_model\n        self.index_name = index_name or self.DEFAULT_VALKEY_INDEX_NAME\n        self.key_prefix = f\"{self.index_name}:\"\n        self._index_dim: int | None = None\n\n        resolved_url = None","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/caching/valkey_semantic_cache.py#L49-L85","documentation":"ValkeySemanticCache.__init__ mirrors its Redis counterpart: similarity_threshold is mandatory, has no default, and None (or omission) raises ValueError immediately. The threshold is what decides whether a cached answer is 'close enough' to reuse, so the constructor refuses to guess.","triggerScenarios":"Constructing litellm.caching.valkey_semantic_cache.ValkeySemanticCache without similarity_threshold; configuring litellm proxy caching with type='valkey-semantic' and omitting the field.","commonSituations":"Copy-pasting a redis-semantic config block (which already has it) minus the threshold; assuming the Valkey cache shares defaults with the plain RedisCache.","solutions":["Pass similarity_threshold explicitly (0.7–0.9 typical), e.g. ValkeySemanticCache(redis_url=..., similarity_threshold=0.8)","Add similarity_threshold to the valkey-semantic cache config block"],"exampleFix":"# before\ncache = ValkeySemanticCache(redis_url='redis://localhost:6379')\n\n# after\ncache = ValkeySemanticCache(redis_url='redis://localhost:6379', similarity_threshold=0.8)","handlingStrategy":"validation","validationCode":"if cfg.get('similarity_threshold') is None:\n    raise ValueError('valkey semantic cache requires similarity_threshold (e.g. 0.8)')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reuse the same required-fields checklist across redis/valkey semantic cache configs"],"tags":["valkey","semantic-cache","configuration","validation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}