langchain-ai/langchain · error · ValueError
`score_threshold` is not specified with a float value(0~1) i
Error message
`score_threshold` is not specified with a float value(0~1) in `search_kwargs`.
What it means
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.
Source
Thrown at libs/core/langchain_core/vectorstores/base.py:1015
Raises:
ValueError: If `search_type` is not one of the allowed search types.
ValueError: If `score_threshold` is not specified with a float value(`0~1`)
"""
search_type = values.get("search_type", "similarity")
if search_type not in cls.allowed_search_types:
msg = (
f"search_type of {search_type} not allowed. Valid values are: "
f"{cls.allowed_search_types}"
)
raise ValueError(msg)
if search_type == "similarity_score_threshold":
score_threshold = values.get("search_kwargs", {}).get("score_threshold")
if (score_threshold is None) or (not isinstance(score_threshold, float)):
msg = (
"`score_threshold` is not specified with a float value(0~1) "
"in `search_kwargs`."
)
raise ValueError(msg)
return values
def _get_ls_params(self, **kwargs: Any) -> LangSmithRetrieverParams:
"""Get standard params for tracing."""
kwargs_ = self.search_kwargs | kwargs
ls_params = super()._get_ls_params(**kwargs_)
ls_params["ls_vector_store_provider"] = self.vectorstore.__class__.__name__
if self.vectorstore.embeddings:
ls_params["ls_embedding_provider"] = (
self.vectorstore.embeddings.__class__.__name__
)
elif hasattr(self.vectorstore, "embedding") and isinstance(
self.vectorstore.embedding, Embeddings
):
ls_params["ls_embedding_provider"] = (View on GitHub (pinned to e32fa9a52e)
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.
Example fix
# before
retriever = store.as_retriever(search_type="similarity_score_threshold")
# after
retriever = store.as_retriever(
search_type="similarity_score_threshold",
search_kwargs={"score_threshold": 0.5},
) Defensive patterns
Strategy: validation
Validate before calling
def validate_retriever_config(search_type: str, search_kwargs: dict) -> None:
if search_type == "similarity_score_threshold":
st = search_kwargs.get("score_threshold")
if st is None or not isinstance(st, float) or not 0.0 <= st <= 1.0:
raise ValueError(
"score_threshold must be a float in [0, 1] inside search_kwargs, "
f"got {st!r}"
) Type guard
def has_valid_score_threshold(search_kwargs: dict) -> bool:
"""True when score_threshold exists and is a float (not int/str)."""
st = search_kwargs.get("score_threshold")
return isinstance(st, float) and 0.0 <= st <= 1.0 Try / catch
from pydantic import ValidationError
try:
retriever = store.as_retriever(
search_type="similarity_score_threshold", search_kwargs=search_kwargs
)
except ValidationError as e:
if "score_threshold" in str(e):
retriever = store.as_retriever(
search_type="similarity_score_threshold",
search_kwargs={**search_kwargs, "score_threshold": 0.5},
)
else:
raise Prevention
- 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.
When it happens
Trigger: `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`).
Common situations: 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.
Related errors
- search_type of {search_type} not allowed. Valid values are:
- maxsize must be greater than 0
- Could not resolve content_key {full_path!r}: expected a mapp
- Could not resolve content_key {full_path!r}: missing key {ke
- If multiple pydantic schemas are provided then args_only sho
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/a1a93d2f5e70d2fd.
Report an issue: GitHub.