MemPalace/mempalace · error · DimensionMismatchError
qdrant collection {self._collection_name!r} expects embeddin
Error message
qdrant collection {self._collection_name!r} expects embedding dimension {self._known_dimension}, got {dimension} What it means
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.
Source
Thrown at mempalace/backends/qdrant.py:745
result = info.get("result") or info
params = (result.get("config") or {}).get("params") or {}
vectors = params.get("vectors") or params.get("vectors_config") or {}
if isinstance(vectors, dict) and "size" in vectors:
return int(vectors["size"])
if isinstance(vectors, dict):
for value in vectors.values():
if isinstance(value, dict) and "size" in value:
return int(value["size"])
return None
def _ensure_remote_collection(self, dimension: int) -> None:
if dimension <= 0:
raise ValueError("embedding dimension must be positive")
with self._lock:
self._ensure_open()
if self._known_dimension is not None:
if self._known_dimension != dimension:
raise DimensionMismatchError(
f"qdrant collection {self._collection_name!r} expects "
f"embedding dimension {self._known_dimension}, got {dimension}"
)
return
if not self._remote_exists():
self._client.create_collection(self._remote_collection, dimension)
self._client.create_payload_index(
self._remote_collection, _PAYLOAD_DOCUMENT, "text"
)
self._known_dimension = dimension
return
remote_dim = self._remote_dimension()
if remote_dim is not None and remote_dim != dimension:
raise DimensionMismatchError(
f"qdrant collection {self._collection_name!r} expects "
f"embedding dimension {remote_dim}, got {dimension}"
)
self._known_dimension = remote_dim or dimensionView on GitHub (pinned to 06cb6987f0)
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
Example fix
# before # collection created with model A (768-dim); now: collection.upsert(..., embeddings=model_b_vectors) # 1024-dim -> DimensionMismatchError # after # re-embed everything with model B into a new collection collection_b.upsert(..., embeddings=[model_b.embed(d) for d in all_docs])
Defensive patterns
Strategy: try-catch
Validate before calling
if known_dim is not None and len(embeddings[0]) != known_dim:
raise ValueError(f"batch dim {len(embeddings[0])} != collection dim {known_dim}; re-embed first") Try / catch
from mempalace.backends.base import DimensionMismatchError
try:
collection.upsert(...)
except DimensionMismatchError as e:
# model changed: route to re-embedding/migration workflow Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- qdrant batch cannot mix embedding dimensions {sorted(dims)}
- embedding dimension must be positive
- qdrant collection {self._collection_name!r} expects embeddin
- qdrant collection {self._collection_name!r} expects embeddin
- milvus batch cannot mix embedding dimensions {sorted(dims)}
AI-assisted analysis of MemPalace/mempalace@06cb6987f0 (2026-08-15).
Data as JSON: /api/errors/62e370ebcd628c73.
Report an issue: GitHub.