{"record":{"id":"1a8a8887629b8ce7","repo":"headroomlabs-ai/headroom","slug":"embedding-dimension-embedding-shape-0-does-not-1a8a88","errorCode":null,"errorMessage":"Embedding dimension {embedding.shape[0]} does not match index dimension {self._dimension}","messagePattern":"Embedding dimension (.+?) does not match index dimension (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"headroom/memory/adapters/sqlite_vector.py","lineNumber":300,"sourceCode":"        rowids: dict[str, int] = {}\n        for chunk in self._chunked(memory_ids):\n            placeholders = \", \".join(\"?\" for _ in chunk)\n            rows = conn.execute(\n                f\"SELECT rowid, memory_id FROM vec_metadata WHERE memory_id IN ({placeholders})\",\n                chunk,\n            ).fetchall()\n            for row in rows:\n                rowids[str(row[\"memory_id\"])] = int(row[\"rowid\"])\n        return rowids\n\n    def _prepare_memory_for_index(self, memory: Memory) -> tuple[np.ndarray, VectorMetadata]:\n        \"\"\"Validate a memory and prepare it for indexing.\"\"\"\n        if memory.embedding is None:\n            raise ValueError(f\"Memory {memory.id} has no embedding\")\n\n        embedding = np.asarray(memory.embedding, dtype=np.float32)\n        if embedding.shape[0] != self._dimension:\n            raise ValueError(\n                f\"Embedding dimension {embedding.shape[0]} does not match \"\n                f\"index dimension {self._dimension}\"\n            )\n\n        return embedding, VectorMetadata.from_memory(memory)\n\n    def _metadata_insert_params(self, memory_id: str, metadata: VectorMetadata) -> tuple[Any, ...]:\n        \"\"\"Build INSERT parameters for vector metadata.\"\"\"\n        return (\n            memory_id,\n            metadata.user_id,\n            metadata.session_id,\n            metadata.agent_id,\n            metadata.importance,\n            metadata.created_at.isoformat(),\n            metadata.valid_until.isoformat() if metadata.valid_until else None,\n            json.dumps(metadata.entity_refs),\n            metadata.content,","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/headroomlabs-ai/headroom/blob/322425c43bffde1ed0b64fecf3cf5951565dd82b/headroom/memory/adapters/sqlite_vector.py#L282-L318","documentation":"Raised by SQLiteVectorIndex._prepare_memory_for_index when the memory's embedding length differs from the dimension the index was created with (default 384 for MiniLM). The vec0 virtual table is fixed-dimension, so mismatched vectors are rejected before insert.","triggerScenarios":"Using the default dimension=384 with an embedder that outputs another size (e.g. 768 or 1536); switching embedding models against an existing database; indexing mixed-source embeddings.","commonSituations":"Relying on the MiniLM default while using OpenAI or another model; model upgrades without recreating the vector table; environments with different embedders sharing one db_path.","solutions":["Pass dimension=embedder.dimension when constructing SQLiteVectorIndex.","If the model changed, drop/recreate the vec0 table (or use a new db_path) and re-index.","Log embedding length at ingest to catch drift early."],"exampleFix":"// before\nindex = SQLiteVectorIndex(db_path=p)  # default 384, embedder gives 1536\n\n// after\nindex = SQLiteVectorIndex(dimension=embedder.dimension, db_path=p)","handlingStrategy":"validation","validationCode":"if np.asarray(memory.embedding).shape[0] != index.dimension:\n    raise RuntimeError(\"embedding/model mismatch against vec0 table\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass dimension=embedder.dimension; do not rely on the 384 default.","Recreate the vector table (or use a new db_path) when changing embedding models."],"tags":["sqlite-vec","dimension-mismatch","embedding","validation"],"backgroundTag":null,"analyzedSha":"322425c43bffde1ed0b64fecf3cf5951565dd82b","analyzedAt":"2026-08-15T01:03:05.481Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}