{"record":{"id":"62e370ebcd628c73","repo":"MemPalace/mempalace","slug":"qdrant-collection-self-collection-name-r-expect","errorCode":null,"errorMessage":"qdrant collection {self._collection_name!r} expects embedding dimension {self._known_dimension}, got {dimension}","messagePattern":"qdrant collection (.+?) expects embedding dimension (.+?), got (.+?)","errorType":"exception","errorClass":"DimensionMismatchError","httpStatus":null,"severity":"error","filePath":"mempalace/backends/qdrant.py","lineNumber":745,"sourceCode":"        result = info.get(\"result\") or info\n        params = (result.get(\"config\") or {}).get(\"params\") or {}\n        vectors = params.get(\"vectors\") or params.get(\"vectors_config\") or {}\n        if isinstance(vectors, dict) and \"size\" in vectors:\n            return int(vectors[\"size\"])\n        if isinstance(vectors, dict):\n            for value in vectors.values():\n                if isinstance(value, dict) and \"size\" in value:\n                    return int(value[\"size\"])\n        return None\n\n    def _ensure_remote_collection(self, dimension: int) -> None:\n        if dimension <= 0:\n            raise ValueError(\"embedding dimension must be positive\")\n        with self._lock:\n            self._ensure_open()\n            if self._known_dimension is not None:\n                if self._known_dimension != dimension:\n                    raise DimensionMismatchError(\n                        f\"qdrant collection {self._collection_name!r} expects \"\n                        f\"embedding dimension {self._known_dimension}, got {dimension}\"\n                    )\n                return\n            if not self._remote_exists():\n                self._client.create_collection(self._remote_collection, dimension)\n                self._client.create_payload_index(\n                    self._remote_collection, _PAYLOAD_DOCUMENT, \"text\"\n                )\n                self._known_dimension = dimension\n                return\n            remote_dim = self._remote_dimension()\n            if remote_dim is not None and remote_dim != dimension:\n                raise DimensionMismatchError(\n                    f\"qdrant collection {self._collection_name!r} expects \"\n                    f\"embedding dimension {remote_dim}, got {dimension}\"\n                )\n            self._known_dimension = remote_dim or dimension","sourceCodeStart":727,"sourceCodeEnd":763,"githubUrl":"https://github.com/MemPalace/mempalace/blob/06cb6987f02610784fefbad4b2bd5d026d164ba6/mempalace/backends/qdrant.py#L727-L763","documentation":"Raised by _ensure_remote_collection() when the collection handle already knows the collection's dimension (self._known_dimension, cached from creation or a prior write/query) and the current batch's embedding dimension differs. DimensionMismatchError (BackendError subclass); the existing data cannot be mixed with a different vector size.","triggerScenarios":"Writing with a 384-dim model to a collection created with 768-dim vectors (or vice versa) within the same process/session where _known_dimension was already set; switching the Ollama embedding model between runs while the process cached the old dimension.","commonSituations":"User switched embed model in config (e.g. from nomic-embed-text to bge-m3) without recreating the palace; two workers with different model configs writing to the same collection; partial migration to a new model.","solutions":["Re-embed all data with the new model into a fresh collection/palace — dimensions can never be mixed","Revert to the original embedding model recorded when the collection was created","Check the embedder identity stored with the collection (get_stored_embedder_identity) and align config","If a model change is intended, export data, create a new palace with the new model, and re-ingest from verbatim sources"],"exampleFix":"# before\n# collection created with model A (768-dim); now:\ncollection.upsert(..., embeddings=model_b_vectors)  # 1024-dim -> DimensionMismatchError\n# after\n# re-embed everything with model B into a new collection\ncollection_b.upsert(..., embeddings=[model_b.embed(d) for d in all_docs])","handlingStrategy":"try-catch","validationCode":"if known_dim is not None and len(embeddings[0]) != known_dim:\n    raise ValueError(f\"batch dim {len(embeddings[0])} != collection dim {known_dim}; re-embed first\")","typeGuard":null,"tryCatchPattern":"from mempalace.backends.base import DimensionMismatchError\ntry:\n    collection.upsert(...)\nexcept DimensionMismatchError as e:\n    # model changed: route to re-embedding/migration workflow","preventionTips":["Store and verify the embedder identity on first use of each collection","Keep one embed model per palace; change models only with a full re-ingest","Fail fast at app start if configured model dim != stored dim"],"tags":["dimension-mismatch","embeddings","qdrant","configuration"],"backgroundTag":null,"analyzedSha":"06cb6987f02610784fefbad4b2bd5d026d164ba6","analyzedAt":"2026-08-15T03:03:36.213Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}