BerriAI/litellm · error · ValueError

similarity_threshold must be provided, passed None

Error message

similarity_threshold must be provided, passed None

What it means

RedisSemanticCache.__init__ requires an explicit similarity_threshold (0.0–1.0) to convert into a cosine-distance threshold; None means the cache cannot decide which stored embeddings count as semantic hits, so construction stops.

Solutions

  1. Pass a non-None similarity_threshold (a float between 0 and 1) when constructing the Redis semantic cache.
  2. Choose a threshold appropriate for your embedding model, e.g. 0.8 as a starting point.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/caching/redis_semantic_cache.py:79 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/64551e87194dbfe1. Report an issue: GitHub.

Appendix: source

Thrown at litellm/caching/redis_semantic_cache.py:79

            similarity_threshold: Threshold for semantic similarity (0.0 to 1.0)
                where 1.0 requires exact matches and 0.0 accepts any match
            embedding_model: Model to use for generating embeddings
            index_name: Name for the Redis index
            ttl: Default time-to-live for cache entries in seconds
            **kwargs: Additional arguments passed to the Redis client

        Raises:
            Exception: If similarity_threshold is not provided or required Redis
                connection information is missing
        """
        if index_name is None:
            index_name = self.DEFAULT_REDIS_INDEX_NAME

        print_verbose(f"Redis semantic-cache initializing index - {index_name}")

        # Validate similarity threshold
        if similarity_threshold is None:
            raise ValueError("similarity_threshold must be provided, passed None")

        # Store configuration
        self.similarity_threshold = similarity_threshold

        # Convert similarity threshold [0,1] to distance threshold [0,2]
        # For cosine distance: 0 = most similar, 2 = least similar
        # While similarity: 1 = most similar, 0 = least similar
        self.distance_threshold = 1 - similarity_threshold
        self.embedding_model = embedding_model

        # Set up Redis connection
        if redis_url is None:
            try:
                # Attempt to use provided parameters or fallback to environment variables
                host = host or os.environ["REDIS_HOST"]
                port = port or os.environ["REDIS_PORT"]
                password = password or os.environ["REDIS_PASSWORD"]
            except KeyError as e:

View on GitHub (pinned to 77b7c6c40c)