MemPalace/mempalace · error · ValueError
embedding dimension must be positive
Error message
embedding dimension must be positive
What it means
Raised by MilvusCollection._ensure_remote_collection() when the dimension argument is <= 0. Before creating or validating the remote Milvus collection the backend sanity-checks the embedding dimension; zero or negative dims (which can slip through when a dim is computed from empty config or parsed as -1 'unknown') are rejected with plain ValueError. Note this is the collection-creation path; batch-level shape errors are caught earlier by _as_vector_array (error 34).
Source
Thrown at mempalace/backends/milvus.py:393
return None
fields = []
if isinstance(info, dict):
fields = info.get("fields") or (info.get("schema") or {}).get("fields") or []
for field in fields:
name = field.get("name") or field.get("field_name")
if name != FIELD_VECTOR:
continue
params = field.get("params") or field.get("type_params") or {}
dim = field.get("dim") or params.get("dim")
try:
return int(dim)
except (TypeError, ValueError):
return None
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"milvus collection {self._collection_name!r} expects "
f"embedding dimension {self._known_dimension}, got {dimension}"
)
return
if not self._remote_exists():
self._backend._create_remote_collection(
self._client,
self._remote_collection,
dimension,
consistency_level=self._config.consistency_level,
)
self._backend._load_remote_collection(self._client, self._remote_collection)
self._known_dimension = dimensionView on GitHub (pinned to 06cb6987f0)
Solutions
- Ensure the embedder is loaded and reports its true dimension (e.g. 384/768) before first add()
- Validate config: dimension must be a positive int, not 0/-1/None
- Lazy-create the collection only after the first real embedding is available
Example fix
# before
dim = embedder.dimension # 0 because model not loaded
collection._ensure_remote_collection(dim)
# after
embedder.load()
dim = embedder.dimension # e.g. 768
assert dim > 0, f"bad embedding dimension: {dim}"
collection._ensure_remote_collection(dim) Defensive patterns
Strategy: validation
Validate before calling
def valid_dimension(dim) -> bool:
return isinstance(dim, int) and not isinstance(dim, bool) and dim > 0 Try / catch
try:
collection.add(ids=ids, documents=docs, embeddings=embs)
except ValueError as e:
if "dimension must be positive" in str(e):
raise RuntimeError("embedder dimension not initialized — load the model before first insert") from e
raise Prevention
- Load the embedder and read its real dimension before any collection write
- Reject 0/-1/None dimensions in config validation at startup
- Create/validate the collection lazily on first real embedding
When it happens
Trigger: Calling add()/query() where the embedder reports dimension 0 (uninitialized model config), or code passing dim=-1 as an 'unknown' sentinel into the collection bootstrap path.
Common situations: Embedder not yet loaded so its dim attribute is 0/None→0; misconfigured embedding model section; custom embedders whose dimension property is computed before initialization.
Related errors
- embedding must be a non-empty 1D vector
- Milvus filter field {name!r} is not a safe identifier
- $in requires a non-empty list for {field!r}
- $nin requires a non-empty list for {field!r}
- milvus batch cannot mix embedding dimensions {sorted(dims)}
AI-assisted analysis of MemPalace/mempalace@06cb6987f0 (2026-08-15).
Data as JSON: /api/errors/172e57acc42d9e9b.
Report an issue: GitHub.