{"record":{"id":"a1a93d2f5e70d2fd","repo":"langchain-ai/langchain","slug":"score-threshold-is-not-specified-with-a-float-va","errorCode":null,"errorMessage":"`score_threshold` is not specified with a float value(0~1) in `search_kwargs`.","messagePattern":"`score_threshold` is not specified with a float value\\(0~1\\) in `search_kwargs`\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/vectorstores/base.py","lineNumber":1015,"sourceCode":"        Raises:\n            ValueError: If `search_type` is not one of the allowed search types.\n            ValueError: If `score_threshold` is not specified with a float value(`0~1`)\n        \"\"\"\n        search_type = values.get(\"search_type\", \"similarity\")\n        if search_type not in cls.allowed_search_types:\n            msg = (\n                f\"search_type of {search_type} not allowed. Valid values are: \"\n                f\"{cls.allowed_search_types}\"\n            )\n            raise ValueError(msg)\n        if search_type == \"similarity_score_threshold\":\n            score_threshold = values.get(\"search_kwargs\", {}).get(\"score_threshold\")\n            if (score_threshold is None) or (not isinstance(score_threshold, float)):\n                msg = (\n                    \"`score_threshold` is not specified with a float value(0~1) \"\n                    \"in `search_kwargs`.\"\n                )\n                raise ValueError(msg)\n        return values\n\n    def _get_ls_params(self, **kwargs: Any) -> LangSmithRetrieverParams:\n        \"\"\"Get standard params for tracing.\"\"\"\n        kwargs_ = self.search_kwargs | kwargs\n\n        ls_params = super()._get_ls_params(**kwargs_)\n\n        ls_params[\"ls_vector_store_provider\"] = self.vectorstore.__class__.__name__\n\n        if self.vectorstore.embeddings:\n            ls_params[\"ls_embedding_provider\"] = (\n                self.vectorstore.embeddings.__class__.__name__\n            )\n        elif hasattr(self.vectorstore, \"embedding\") and isinstance(\n            self.vectorstore.embedding, Embeddings\n        ):\n            ls_params[\"ls_embedding_provider\"] = (","sourceCodeStart":997,"sourceCodeEnd":1033,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/vectorstores/base.py#L997-L1033","documentation":"Companion validation in the `VectorStoreRetriever` field validator: when `search_type='similarity_score_threshold'`, the retriever requires `search_kwargs['score_threshold']` to be present and to be a `float` between 0 and 1. Without a threshold the filtered search has no cutoff, so construction is rejected.","triggerScenarios":"`as_retriever(search_type='similarity_score_threshold')` with no `search_kwargs`, with `score_threshold` missing from `search_kwargs`, or with a non-float value such as the string `\"0.5\"` or the integer `1` (note `isinstance(1, float)` is `False`).","commonSituations":"Switching `search_type` to `'similarity_score_threshold'` but leaving `search_kwargs` empty; JSON/YAML config parsing thresholds as strings; passing `score_threshold=1` (int) instead of `1.0`; forgetting the key lives inside `search_kwargs`, not top-level.","solutions":["Add a float threshold inside `search_kwargs`: `as_retriever(search_type='similarity_score_threshold', search_kwargs={'score_threshold': 0.5})`.","Cast config-loaded values: `float(config['score_threshold'])`.","Ensure the literal is a float (`0.75`, `1.0`), not an int or string."],"exampleFix":"# before\nretriever = store.as_retriever(search_type=\"similarity_score_threshold\")\n\n# after\nretriever = store.as_retriever(\n    search_type=\"similarity_score_threshold\",\n    search_kwargs={\"score_threshold\": 0.5},\n)","handlingStrategy":"validation","validationCode":"def validate_retriever_config(search_type: str, search_kwargs: dict) -> None:\n    if search_type == \"similarity_score_threshold\":\n        st = search_kwargs.get(\"score_threshold\")\n        if st is None or not isinstance(st, float) or not 0.0 <= st <= 1.0:\n            raise ValueError(\n                \"score_threshold must be a float in [0, 1] inside search_kwargs, \"\n                f\"got {st!r}\"\n            )","typeGuard":"def has_valid_score_threshold(search_kwargs: dict) -> bool:\n    \"\"\"True when score_threshold exists and is a float (not int/str).\"\"\"\n    st = search_kwargs.get(\"score_threshold\")\n    return isinstance(st, float) and 0.0 <= st <= 1.0","tryCatchPattern":"from pydantic import ValidationError\n\ntry:\n    retriever = store.as_retriever(\n        search_type=\"similarity_score_threshold\", search_kwargs=search_kwargs\n    )\nexcept ValidationError as e:\n    if \"score_threshold\" in str(e):\n        retriever = store.as_retriever(\n            search_type=\"similarity_score_threshold\",\n            search_kwargs={**search_kwargs, \"score_threshold\": 0.5},\n        )\n    else:\n        raise","preventionTips":["Always pass `score_threshold` as a float literal (`0.5`, not `\"0.5\"` or `1`).","When loading config from JSON/YAML, cast with `float(...)` at load time.","Remember the threshold lives inside `search_kwargs`, not as a top-level argument."],"tags":["retriever","vector-store","validation","configuration"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}