{"record":{"id":"be400c57335f1f0a","repo":"run-llama/llama_index","slug":"invalid-query-mode-query-mode","errorCode":null,"errorMessage":"Invalid query mode: {query.mode}","messagePattern":"Invalid query mode: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/vector_stores/simple.py","lineNumber":310,"sourceCode":"            )\n        elif query.mode == MMR_MODE:\n            mmr_threshold = kwargs.get(\"mmr_threshold\")\n            top_similarities, top_ids = get_top_k_mmr_embeddings(\n                query_embedding,\n                embeddings,\n                similarity_top_k=query.similarity_top_k,\n                embedding_ids=node_ids,\n                mmr_threshold=mmr_threshold,\n            )\n        elif query.mode == VectorStoreQueryMode.DEFAULT:\n            top_similarities, top_ids = get_top_k_embeddings(\n                query_embedding,\n                embeddings,\n                similarity_top_k=query.similarity_top_k,\n                embedding_ids=node_ids,\n            )\n        else:\n            raise ValueError(f\"Invalid query mode: {query.mode}\")\n\n        return VectorStoreQueryResult(\n            similarities=top_similarities,\n            ids=top_ids,\n        )\n\n    def persist(\n        self,\n        persist_path: str = os.path.join(DEFAULT_PERSIST_DIR, DEFAULT_PERSIST_FNAME),\n        fs: Optional[fsspec.AbstractFileSystem] = None,\n    ) -> None:\n        \"\"\"Persist the SimpleVectorStore to a directory.\"\"\"\n        fs = fs or self._fs\n        dirpath = os.path.dirname(persist_path)\n        if not fs.exists(dirpath):\n            fs.makedirs(dirpath)\n\n        with fs.open(persist_path, \"w\", encoding=\"utf-8\") as f:","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/vector_stores/simple.py#L292-L328","documentation":"SimpleVectorStore.query() implements only a fixed set of VectorStoreQueryMode branches (default top-k similarity and MMR, plus the modes handled above the shown region); any other mode falls through to `raise ValueError(f\"Invalid query mode: {query.mode}\")`. The message interpolates the mode name at raise time, so the thrown text contains the actual enum value. It signals that the in-memory store does not support the requested retrieval strategy (e.g. sparse, hybrid, SVM regex modes).","triggerScenarios":"Constructing a retriever with `vector_store_query_mode=VectorStoreQueryMode.SPARSE` / `HYBRID` / `SVM` / `REGEX` etc. against the default SimpleVectorStore; using `QueryEngine(..., mode=...)` or `VectorStoreQuery(mode=...)` with an unsupported enum member and passing it to `simple_store.query()`.","commonSituations":"Copy-pasting retriever configs from examples that use Milvus/Weaviate/Pinecone hybrid search; upgrading retrieval strategies without swapping the backend; exploratory code iterating over all VectorStoreQueryMode values.","solutions":["Use `VectorStoreQueryMode.DEFAULT` (or MMR, which SimpleVectorStore supports) for the in-memory store.","Switch to a vector store integration that implements the mode you need (e.g. Pinecone/Qdrant/Milvus for hybrid or sparse).","Check `query.mode` against the store's supported set before querying when the backend is configurable."],"exampleFix":"# before\nretriever = VectorIndexRetriever(index=index, vector_store_query_mode=VectorStoreQueryMode.SPARSE)\n\n# after\nretriever = VectorIndexRetriever(index=index, vector_store_query_mode=VectorStoreQueryMode.DEFAULT)","handlingStrategy":"validation","validationCode":"SIMPLE_STORE_MODES = {VectorStoreQueryMode.DEFAULT, VectorStoreQueryMode.MMR}\n\ndef mode_supported(mode) -> bool:\n    return mode in SIMPLE_STORE_MODES","typeGuard":null,"tryCatchPattern":"try:\n    result = store.query(query)\nexcept ValueError as e:\n    if \"query mode\" in str(e):\n        query.mode = VectorStoreQueryMode.DEFAULT\n        result = store.query(query)\n    else:\n        raise","preventionTips":["Match the query mode to the store's documented capabilities before building the retriever.","Default to DEFAULT mode unless you know the backend supports sparse/hybrid.","Centralize mode selection in config so backend swaps adjust it automatically."],"tags":["vector-store","query-mode","not-supported","python"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}