{"record":{"id":"91f7a26e637c3a83","repo":"RyanCodrai/turbovec","slug":"query-embedding-dim-qvec-shape-1-does-not-match","errorCode":null,"errorMessage":"query_embedding dim {qvec.shape[1]} does not match store dim {expected_dim}","messagePattern":"query_embedding dim (.+?) does not match store dim (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"turbovec-python/python/turbovec/haystack.py","lineNumber":625,"sourceCode":"\n        # Up-front validation, matching the reference: an empty or\n        # non-numeric query embedding is a caller error regardless of\n        # whether the store happens to be empty (issue #301). `Real`\n        # rather than the reference's `isinstance(..., float)` so numpy\n        # scalars and ints are accepted.\n        if len(query_embedding) == 0 or not isinstance(query_embedding[0], Real):\n            raise ValueError(\"query_embedding should be a non-empty list of floats.\")\n\n        if self.count_documents() == 0:\n            return []\n\n        qvec = np.asarray(query_embedding, dtype=np.float32)\n        if qvec.ndim == 1:\n            qvec = qvec[None, :]\n        # By this point n_documents > 0, so the index has a committed dim.\n        expected_dim = self._index.dim\n        if qvec.shape[1] != expected_dim:\n            raise ValueError(\n                f\"query_embedding dim {qvec.shape[1]} does not match store dim {expected_dim}\"\n            )\n        # Cosine mode: normalize the query so the raw score against unit\n        # document vectors is true cosine similarity.\n        if self._vectors_normalized:\n            qvec = l2_normalize_rows(qvec)\n        if not qvec.flags[\"C_CONTIGUOUS\"]:\n            qvec = np.ascontiguousarray(qvec)\n\n        if not filters:\n            fetch_k = min(top_k, self.count_documents())\n            scores, handles = self._index.search(qvec, fetch_k)\n        else:\n            self._validate_filters(filters)\n            for _attempt in range(8):\n                # Resolve filter → handle allowlist by walking the in-memory\n                # doc table once. This is the same O(N) cost as the old\n                # post-filter pass, just moved upfront so the kernel can","sourceCodeStart":607,"sourceCodeEnd":643,"githubUrl":"https://github.com/RyanCodrai/turbovec/blob/ccab9f325e6ce2a270a87daf01ae4e443bcf2d49/turbovec-python/python/turbovec/haystack.py#L607-L643","documentation":"Raised in embedding_retrieval when the query vector's width differs from the store's committed dimension (self._index.dim). The query was embedded with a different model or configuration than the documents in the store, so similarity scoring would be meaningless.","triggerScenarios":"Thrown at turbovec-python/python/turbovec/haystack.py:625 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Embed queries with the same embedder used to index the documents.","Create/rebuild the store with the current embedder if the model intentionally changed.","Catch the ValueError to surface embedder/store mismatch in retrieval pipelines instead of returning wrong results."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"ccab9f325e6ce2a270a87daf01ae4e443bcf2d49","analyzedAt":"2026-09-06T08:39:18.516Z","contentChangedAt":"2026-09-06T08:39:18.516Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}