{"record":{"id":"21d6b0ab0cee57f6","repo":"RyanCodrai/turbovec","slug":"embedding-dimension-vectors-shape-1-does-not-ma","errorCode":null,"errorMessage":"embedding dimension {vectors.shape[1]} does not match index dim {existing_dim}","messagePattern":"embedding dimension (.+?) does not match index dim (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"turbovec-python/python/turbovec/langchain.py","lineNumber":407,"sourceCode":"            ids = [ids[i] for i in keep]\n            texts_list = [texts_list[i] for i in keep]\n            metadatas = [metadatas[i] for i in keep]\n            vectors = vectors[keep]\n\n        # Cosine mode: L2-normalize outside the lock (pure computation,\n        # like the embedding step) so the engine's raw inner product is\n        # true cosine similarity. Zero rows pass through unchanged.\n        if self._similarity == COSINE:\n            vectors = l2_normalize_rows(vectors)\n\n        with self._write_lock:\n            # Validate before mutating any existing data. IdMapIndex.add_with_ids\n            # handles both eager (dim must match) and lazy (locks dim on first\n            # call) cases. Pre-check the eager case so we surface a clean\n            # ValueError rather than a Rust panic.\n            existing_dim = self._index.dim\n            if existing_dim is not None and vectors.shape[1] != existing_dim:\n                raise ValueError(\n                    f\"embedding dimension {vectors.shape[1]} does not match index dim {existing_dim}\"\n                )\n            if not vectors.flags[\"C_CONTIGUOUS\"]:\n                vectors = np.ascontiguousarray(vectors)\n\n            handles = np.array(\n                [self._issue_handle() for _ in texts_list], dtype=np.uint64\n            )\n\n            # Capture the previous state of any upserted id BEFORE the maps\n            # are overwritten, so a failed index add can restore it and the\n            # old vectors can be dropped once the add succeeds.\n            old = [\n                (i, self._str_to_u64[i], self._docs[i])\n                for i in ids\n                if i in self._str_to_u64\n            ]\n","sourceCodeStart":389,"sourceCodeEnd":425,"githubUrl":"https://github.com/RyanCodrai/turbovec/blob/ccab9f325e6ce2a270a87daf01ae4e443bcf2d49/turbovec-python/python/turbovec/langchain.py#L389-L425","documentation":"Raised in _store_texts_and_vectors under the write lock when the batch's embedding width differs from the index's committed dim (self._index.dim). Pre-checked so the eager-dimension mismatch surfaces as a clean ValueError rather than a Rust panic; the embedder used for these texts differs from the one the index was built with.","triggerScenarios":"Thrown at turbovec-python/python/turbovec/langchain.py:407 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Re-embed texts with the same embedder used to create the index.","Create a fresh TurboQuantVectorStore if the embedding model intentionally changed.","Catch the ValueError to detect embedder/store drift before any vector is written."],"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-14T05:17:10.506Z"}