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 {int(q.size)}

What it means

Raised by QdrantCollection.query() when a query embedding's dimension differs from the collection's known vector size (cached, or fetched from the remote collection config at query time). DimensionMismatchError: queries must use the same embedding model family/dimension as the stored data or vector similarity is meaningless.

Source

Thrown at mempalace/backends/qdrant.py:991

                raise CollectionNotInitializedError(self._collection_name)
            return QueryResult.empty(
                num_queries=len(query_embeddings),
                embeddings_requested=bool(include and "embeddings" in include),
            )

        spec = _IncludeSpec.resolve(include, default_distances=True)
        q_filter = _qdrant_filter(where)
        outer_ids: list[list[str]] = []
        outer_docs: list[list[str]] = []
        outer_metas: list[list[dict]] = []
        outer_dists: list[list[float]] = []
        outer_embeds: list[list[list[float]]] = []
        for query_vector in query_embeddings:
            q = _as_vector_array(query_vector)
            if self._known_dimension is None:
                self._known_dimension = self._remote_dimension()
            if self._known_dimension is not None and int(q.size) != self._known_dimension:
                raise DimensionMismatchError(
                    f"qdrant collection {self._collection_name!r} expects "
                    f"embedding dimension {self._known_dimension}, got {int(q.size)}"
                )
            points = self._client.query_points(
                self._remote_collection,
                vector=q.astype(float).tolist(),
                limit=n_results,
                qdrant_filter=q_filter,
                with_vector=spec.embeddings,
            )
            rows = [_payload_row(point) for point in points]
            outer_ids.append([row["id"] for row in rows])
            outer_docs.append([row["document"] for row in rows] if spec.documents else [])
            outer_metas.append([row["metadata"] for row in rows] if spec.metadatas else [])
            outer_dists.append(
                [_qdrant_score_to_distance(row["score"]) for row in rows] if spec.distances else []
            )
            if spec.embeddings:

View on GitHub (pinned to 06cb6987f0)

Solutions

  1. Embed queries with exactly the model used for ingest (check get_stored_embedder_identity)
  2. Migrate the collection: re-embed all documents with the new model (new collection), then query with that model
  3. Centralize embedder config in one place so ingest and search cannot diverge
  4. The error message states expected vs got dims — confirm against your models' output sizes

Example fix

# before
# collection built with 768-dim model A; querying with 384-dim model B:
collection.query(query_embeddings=[model_b.embed(q)])  # DimensionMismatchError
// after
collection.query(query_embeddings=[model_a.embed(q)])  # same model as ingest
Defensive patterns

Strategy: try-catch

Validate before calling

dim = collection._remote_dimension() or collection._known_dimension
if dim is not None and len(query_vec) != dim:
    raise ValueError(f"query dim {len(query_vec)} != collection dim {dim}; wrong embed model?")

Try / catch

from mempalace.backends.base import DimensionMismatchError
try:
    res = collection.query(query_embeddings=[qvec])
except DimensionMismatchError:
    qvec = ingest_model.embed(query_text)  # re-embed with the ingest-time model

Prevention

When it happens

Trigger: Querying a 768-dim collection with 384-dim query vectors — embedding the query with a different model than the one that built the collection; or after switching the local embed model between ingest and search without rebuilding.

Common situations: Ollama model changed (e.g. default pulled model differs) between indexing and querying; search path uses a hardcoded/different embedder than the ingest path; multiple apps sharing the Qdrant collection with different model configs.

Related errors


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