{"record":{"id":"7ee20b1b238c0ec9","repo":"MemPalace/mempalace","slug":"pgvector-collection-self-collection-name-r-expe-7ee20b","errorCode":null,"errorMessage":"pgvector collection {self._collection_name!r} expects embedding dimension {self._known_dimension}, got {int(q.size)}","messagePattern":"pgvector collection (.+?) expects embedding dimension (.+?), got (.+?)","errorType":"exception","errorClass":"DimensionMismatchError","httpStatus":null,"severity":"error","filePath":"mempalace/backends/pgvector.py","lineNumber":1116,"sourceCode":"        if not self._table_exists():\n            if self._marker_exists():\n                raise CollectionNotInitializedError(self._collection_name)\n            return QueryResult.empty(\n                num_queries=len(query_embeddings),\n                embeddings_requested=bool(include and \"embeddings\" in include),\n            )\n        spec = _IncludeSpec.resolve(include, default_distances=True)\n        outer_ids: list[list[str]] = []\n        outer_docs: list[list[str]] = []\n        outer_metas: list[list[dict]] = []\n        outer_dists: list[list[float]] = []\n        outer_embeds: list[list[list[float]]] = []\n        for query_vector in query_embeddings:\n            q = _as_vector_array(query_vector)\n            if self._known_dimension is None:\n                self._known_dimension = self._client.table_dimension(self._table)\n            if self._known_dimension is not None and int(q.size) != self._known_dimension:\n                raise DimensionMismatchError(\n                    f\"pgvector collection {self._collection_name!r} expects \"\n                    f\"embedding dimension {self._known_dimension}, got {int(q.size)}\"\n                )\n            rows = self._client.query_rows(\n                self._table,\n                vector=q.astype(float).tolist(),\n                limit=n_results,\n                where=where,\n                with_embedding=spec.embeddings,\n            )\n            outer_ids.append([row[\"id\"] for row in rows])\n            outer_docs.append([row[\"document\"] for row in rows] if spec.documents else [])\n            outer_metas.append([row[\"metadata\"] for row in rows] if spec.metadatas else [])\n            outer_dists.append(\n                [float(row[\"distance\"]) if row[\"distance\"] is not None else 1.0 for row in rows]\n                if spec.distances\n                else []\n            )","sourceCodeStart":1098,"sourceCodeEnd":1134,"githubUrl":"https://github.com/MemPalace/mempalace/blob/06cb6987f02610784fefbad4b2bd5d026d164ba6/mempalace/backends/pgvector.py#L1098-L1134","documentation":"Each PostgreSQL table backing a pgvector collection is created with one fixed embedding dimension (recorded and cached as _known_dimension). When a query vector's size differs, the backend raises DimensionMismatchError because pgvector's index and distance operators cannot mix dimensions — the query would either fail in SQL or match nothing. The expected and received dimensions are both included in the message.","triggerScenarios":"Calling query(query_embeddings=[[1.0, 2.0]]) against a collection whose table was built with 384-dimensional vectors; switching embedder models (e.g. all-MiniLM-L6-v2 384d → nomic-embed-text 768d) without rebuilding the collection; a single malformed short vector inside the batch.","commonSituations":"Changing the Ollama embedding model after the palace was built; mixing embeddings from different providers in one codebase; manually hand-crafting a test vector with the wrong length.","solutions":["Re-embed your query with the same model used to build the collection (check the embedder sidecar recorded next to the marker).","If you intentionally switched embedders, recreate the collection/table and re-ingest so all vectors share the new dimension.","Inspect the collection dimension first (it is reported in maintenance/describe stats) and validate your vectors against it."],"exampleFix":"# before\n# collection built with 384-dim MiniLM\ncol.query(query_embeddings=[nomic_768d_vector], n_results=5)\n\n# after\n# same embedder as ingest:\ncol.query(query_embeddings=[minilm_384d_vector], n_results=5)","handlingStrategy":"type-guard","validationCode":"dim = collection_dimension  # from backend describe/maintenance stats\nvecs = [v for v in vecs if len(v) == dim]\ncol.query(query_embeddings=vecs, n_results=5)","typeGuard":"def matches_dimension(vectors, dim: int) -> bool:\n    return all(len(v) == dim for v in vectors)","tryCatchPattern":"from mempalace.backends.base import DimensionMismatchError\ntry:\n    col.query(query_embeddings=vecs, n_results=5)\nexcept DimensionMismatchError as e:\n    logger.error(\"embedder model changed; rebuild collection\", exc_info=e)\n    raise","preventionTips":["Pin the embedder model in configuration and record it next to collections.","After switching embedder models, recreate and re-ingest collections before querying.","Add a startup check comparing your embedder's output dimension to the collection's known dimension."],"tags":["pgvector","embeddings","dimension-mismatch","config-drift"],"backgroundTag":null,"analyzedSha":"06cb6987f02610784fefbad4b2bd5d026d164ba6","analyzedAt":"2026-08-15T03:03:36.213Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}