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 dimension

View on GitHub (pinned to 06cb6987f0)

Solutions

  1. Re-embed all data with the new model into a fresh collection/palace — dimensions can never be mixed
  2. Revert to the original embedding model recorded when the collection was created
  3. Check the embedder identity stored with the collection (get_stored_embedder_identity) and align config
  4. 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

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


AI-assisted analysis of MemPalace/mempalace@06cb6987f0 (2026-08-15). Data as JSON: /api/errors/62e370ebcd628c73. Report an issue: GitHub.