{"record":{"id":"8ad23f9f67b9c5a9","repo":"langchain-ai/langchain","slug":"search-type-of-search-type-not-allowed-expected","errorCode":null,"errorMessage":"search_type of {search_type} not allowed. Expected search_type to be 'similarity', 'similarity_score_threshold' or 'mmr'.","messagePattern":"search_type of (.+?) not allowed\\. Expected search_type to be 'similarity', 'similarity_score_threshold' or 'mmr'\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/vectorstores/base.py","lineNumber":324,"sourceCode":"        Raises:\n            ValueError: If `search_type` is not one of `'similarity'`,\n                `'mmr'`, or `'similarity_score_threshold'`.\n        \"\"\"\n        if search_type == \"similarity\":\n            return self.similarity_search(query, **kwargs)\n        if search_type == \"similarity_score_threshold\":\n            docs_and_similarities = self.similarity_search_with_relevance_scores(\n                query, **kwargs\n            )\n            return [doc for doc, _ in docs_and_similarities]\n        if search_type == \"mmr\":\n            return self.max_marginal_relevance_search(query, **kwargs)\n        msg = (\n            f\"search_type of {search_type} not allowed. Expected \"\n            \"search_type to be 'similarity', 'similarity_score_threshold'\"\n            \" or 'mmr'.\"\n        )\n        raise ValueError(msg)\n\n    async def asearch(\n        self, query: str, search_type: str, **kwargs: Any\n    ) -> list[Document]:\n        \"\"\"Async return docs most similar to query using a specified search type.\n\n        Args:\n            query: Input text.\n            search_type: Type of search to perform.\n\n                Can be `'similarity'`, `'mmr'`, or `'similarity_score_threshold'`.\n            **kwargs: Arguments to pass to the search method.\n\n        Returns:\n            List of `Document` objects most similar to the query.\n\n        Raises:\n            ValueError: If `search_type` is not one of `'similarity'`,","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/vectorstores/base.py#L306-L342","documentation":"`VectorStore.search(query, search_type, ...)` dispatches on the `search_type` string; anything other than `'similarity'`, `'similarity_score_threshold'`, or `'mmr'` raises `ValueError`. The strictness exists because a typo would otherwise silently fall through to no search at all.","triggerScenarios":"Calling `store.search(q, search_type='similiarity')` (typo), `search_type='similarity_score'`, or a custom type the base class does not know; passing user-supplied config directly as `search_type`.","commonSituations":"Config files with misspelled search types; version drift where an integration once accepted an extra type; UI dropdowns that emit values not matching the three allowed strings; case sensitivity issues (`'MMR'`).","solutions":["Set `search_type` to exactly one of `'similarity'`, `'similarity_score_threshold'`, or `'mmr'`.","Validate/normalize external input before passing it: lowercase it and check membership in the allowed set.","For custom search modes, call the underlying method directly (e.g. `store.max_marginal_relevance_search(...)`) instead of the dispatcher."],"exampleFix":"# before\ndocs = store.search(query, search_type=\"similarity_score\")  # ValueError\n\n# after\ndocs = store.search(query, search_type=\"similarity_score_threshold\", score_threshold=0.5)","handlingStrategy":"validation","validationCode":"ALLOWED = {\"similarity\", \"similarity_score_threshold\", \"mmr\"}\n\nsearch_type = (search_type or \"similarity\").lower()\nif search_type not in ALLOWED:\n    raise ValueError(f\"search_type must be one of {sorted(ALLOWED)}, got {search_type!r}\")\ndocs = store.search(query, search_type, **search_kwargs)","typeGuard":"def is_valid_search_type(value: str) -> bool:\n    \"\"\"Type/narrowing guard for VectorStore.search dispatch values.\"\"\"\n    return isinstance(value, str) and value in {\n        \"similarity\", \"similarity_score_threshold\", \"mmr\"\n    }","tryCatchPattern":"try:\n    docs = store.search(query, search_type)\nexcept ValueError as e:\n    if \"search_type\" in str(e):\n        docs = store.search(query, \"similarity\")  # safe fallback\n    else:\n        raise","preventionTips":["Normalize external `search_type` input (strip, lowercase) and whitelist-check it.","Centralize the allowed-values constant next to your config parsing so UI and config share one source of truth.","For custom modes, call the specific search method directly instead of the dispatcher."],"tags":["vector-store","validation","retrieval"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}