{"record":{"id":"6231199064169925","repo":"RyanCodrai/turbovec","slug":"expected-2d-embedding-batch-got-vectors-ndim-d-623119","errorCode":null,"errorMessage":"expected 2D embedding batch, got {vectors.ndim}D","messagePattern":"expected 2D embedding batch, got (.+?)D","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"turbovec-python/python/turbovec/langchain.py","lineNumber":365,"sourceCode":"        # See add_documents: materialize one-shot iterables once.\n        documents = list(documents)\n        texts = [doc.page_content for doc in documents]\n        metadatas = [doc.metadata for doc in documents]\n        if ids is None:\n            ids = [doc.id or str(uuid.uuid4()) for doc in documents]\n        return await self.aadd_texts(\n            texts=texts, metadatas=metadatas, ids=ids, **kwargs\n        )\n\n    def _store_texts_and_vectors(\n        self,\n        texts_list: list[str],\n        vectors: np.ndarray,\n        metadatas: list[dict],\n        ids: list[str],\n    ) -> list[str]:\n        if vectors.ndim != 2:\n            raise ValueError(f\"expected 2D embedding batch, got {vectors.ndim}D\")\n\n        # Validate every metadata entry before touching any state. A bad\n        # entry (e.g. None) previously blew up as `dict(None)` mid-loop,\n        # *after* the vectors had been added to the index — leaving the\n        # docstore and index desynced in memory (and dump() would persist\n        # the corruption). The reference InMemoryVectorStore rejects bad\n        # metadata with a named error; mirror that here.\n        for i, meta in enumerate(metadatas):\n            if not isinstance(meta, dict):\n                raise TypeError(\n                    f\"metadatas[{i}] must be a dict, \"\n                    f\"got {type(meta).__name__}\"\n                )\n\n        # Dedup intra-batch duplicate ids, keeping the last occurrence —\n        # matches InMemoryVectorStore, whose dict store silently overwrites\n        # on a repeated id. Without this every row is added to the index but\n        # _str_to_u64 keeps only the last handle per id, orphaning the","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/RyanCodrai/turbovec/blob/ccab9f325e6ce2a270a87daf01ae4e443bcf2d49/turbovec-python/python/turbovec/langchain.py#L347-L383","documentation":"Raised in _store_texts_and_vectors when the vector batch is not a 2D (N, dim) matrix — the input to add_texts collapsed to 0D (empty) or 1D/3D (wrong rank). This is the last-line shape guard for embedder outputs that passed the earlier row-count/dim-0 checks.","triggerScenarios":"Thrown at turbovec-python/python/turbovec/langchain.py:365 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the embedder returns one flat vector per text so np.asarray yields a 2D float32 matrix.","Check for empty input batches or nested/ragged embedding lists.","Catch the ValueError to abort before any metadata validation or index mutation."],"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"}