{"record":{"id":"cdfa8d0408e9a4b2","repo":"langchain-ai/langchain","slug":"search-type-of-search-type-not-allowed-valid-va","errorCode":null,"errorMessage":"search_type of {search_type} not allowed. Valid values are: {cls.allowed_search_types}","messagePattern":"search_type of (.+?) not allowed\\. Valid values are: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/vectorstores/base.py","lineNumber":1007,"sourceCode":"        \"\"\"Validate search type.\n\n        Args:\n            values: Values to validate.\n\n        Returns:\n            Validated values.\n\n        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","sourceCodeStart":989,"sourceCodeEnd":1025,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/vectorstores/base.py#L989-L1025","documentation":"Pydantic field validator on `VectorStoreRetriever` (`as_retriever()` result): `search_type` must be in the class's `allowed_search_types` (default `{'similarity', 'similarity_score_threshold', 'mmr'}`), otherwise construction fails with `ValueError` listing the permitted values. It guards the retriever config at creation time rather than at query time.","triggerScenarios":"`vectorstore.as_retriever(search_type='foo')`, constructing `VectorStoreRetriever(vectorstore=..., search_type='top_k')`, or a subclass narrowing `allowed_search_types` and then passing a now-disallowed standard value.","commonSituations":"Typos in retriever config; copying `search_type` values valid for a vector store subclass but not the base retriever; custom retriever subclasses that restricted `allowed_search_types` while callers still send `'mmr'`.","solutions":["Pass a valid `search_type`: `'similarity'`, `'similarity_score_threshold'`, or `'mmr'` (or whatever the subclass's `allowed_search_types` contains).","If you extended a subclass with a new mode, add it to `allowed_search_types` and handle it in `_get_relevant_documents`.","Check `VectorStoreRetriever.allowed_search_types` at runtime when search_type comes from config."],"exampleFix":"# before\nretriever = store.as_retriever(search_type=\"similarity_threshold\")  # ValueError\n\n# after\nretriever = store.as_retriever(\n    search_type=\"similarity_score_threshold\",\n    search_kwargs={\"score_threshold\": 0.5},\n)","handlingStrategy":"validation","validationCode":"from langchain_core.vectorstores import VectorStoreRetriever\n\nALLOWED = set(VectorStoreRetriever.allowed_search_types)\n\nif search_type not in ALLOWED:\n    raise ValueError(f\"search_type must be one of {sorted(ALLOWED)}, got {search_type!r}\")\nretriever = store.as_retriever(search_type=search_type, **kwargs)","typeGuard":"def is_allowed_retriever_search_type(value: str) -> bool:\n    \"\"\"Check against the retriever class's allowed_search_types.\"\"\"\n    return isinstance(value, str) and value in VectorStoreRetriever.allowed_search_types","tryCatchPattern":"from pydantic import ValidationError\n\ntry:\n    retriever = store.as_retriever(search_type=search_type)\nexcept ValidationError as e:\n    if \"search_type\" in str(e):\n        retriever = store.as_retriever()  # default 'similarity'\n    else:\n        raise","preventionTips":["Validate `search_type` against `allowed_search_types` before calling `as_retriever`.","When subclassing retrievers, keep `allowed_search_types` in sync with the dispatch you implement.","Surface the allowed values in config schemas/enums instead of free-text fields."],"tags":["retriever","vector-store","validation","pydantic"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}