{"record":{"id":"3bcedd706f560899","repo":"BerriAI/litellm","slug":"similarity-threshold-must-be-provided-passed-none","errorCode":null,"errorMessage":"similarity_threshold must be provided, passed None","messagePattern":"similarity_threshold must be provided, passed None","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/caching/qdrant_semantic_cache.py","lineNumber":57,"sourceCode":"        embedding_model=\"text-embedding-ada-002\",\n        host_type=None,\n        vector_size=None,\n    ):\n        from litellm.llms.custom_httpx.http_handler import (\n            _get_httpx_client,\n            get_async_httpx_client,\n            httpxSpecialProvider,\n        )\n        from litellm.secret_managers.main import get_secret_str\n\n        if collection_name is None:\n            raise Exception(\"collection_name must be provided, passed None\")\n\n        self.collection_name = collection_name\n        print_verbose(f\"qdrant semantic-cache initializing COLLECTION - {self.collection_name}\")\n\n        if similarity_threshold is None:\n            raise Exception(\"similarity_threshold must be provided, passed None\")\n        self.similarity_threshold = similarity_threshold\n        self.embedding_model = embedding_model\n        self.vector_size = vector_size if vector_size is not None else QDRANT_VECTOR_SIZE\n        headers = {}\n\n        # check if defined as os.environ/ variable\n        if qdrant_api_base:\n            if isinstance(qdrant_api_base, str) and qdrant_api_base.startswith(\"os.environ/\"):\n                qdrant_api_base = get_secret_str(qdrant_api_base)\n        if qdrant_api_key:\n            if isinstance(qdrant_api_key, str) and qdrant_api_key.startswith(\"os.environ/\"):\n                qdrant_api_key = get_secret_str(qdrant_api_key)\n\n        qdrant_api_base = qdrant_api_base or os.getenv(\"QDRANT_URL\") or os.getenv(\"QDRANT_API_BASE\")\n        qdrant_api_key = qdrant_api_key or os.getenv(\"QDRANT_API_KEY\")\n        headers = {\"Content-Type\": \"application/json\"}\n        if qdrant_api_key:\n            headers[\"api-key\"] = qdrant_api_key","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/caching/qdrant_semantic_cache.py#L39-L75","documentation":"QdrantSemanticCache.__init__ requires similarity_threshold to be explicitly set; None is rejected because the threshold controls which cached responses count as semantic matches. There is no default value, so the constructor refuses to build a cache that could silently return unrelated cached answers. The exception is raised during construction, before any Qdrant request.","triggerScenarios":"Calling QdrantSemanticCache(...) without similarity_threshold, or with similarity_threshold=None explicitly; building the cache from a config mapping that omits the key.","commonSituations":"Copying a partial example from docs that sets collection_name but not the threshold; migrating from RedisCache (which has no such parameter) to the Qdrant semantic cache and assuming defaults exist.","solutions":["Pass similarity_threshold explicitly (typically 0.7–0.9 for cosine similarity), e.g. QdrantSemanticCache(collection_name='c', similarity_threshold=0.8, ...)","Validate your cache config dict contains similarity_threshold before constructing the cache"],"exampleFix":"# before\ncache = QdrantSemanticCache(collection_name='litellm-cache', qdrant_api_base=url)\n\n# after\ncache = QdrantSemanticCache(collection_name='litellm-cache', similarity_threshold=0.8, qdrant_api_base=url)","handlingStrategy":"validation","validationCode":"def check_semantic_cfg(cfg: dict) -> None:\n    if cfg.get('similarity_threshold') is None:\n        raise ValueError('qdrant semantic cache requires similarity_threshold (try 0.8)')\n    if not 0.0 <= float(cfg['similarity_threshold']) <= 1.0:\n        raise ValueError('similarity_threshold must be within [0, 1]')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat similarity_threshold as required in every config template for semantic caches","Codify cache-config schemas (pydantic) so startup rejects omissions with clear messages"],"tags":["qdrant","semantic-cache","configuration","validation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}