MemPalace/mempalace · error · ValueError
metadatas length {len(metadatas)} does not match ids length
Error message
metadatas length {len(metadatas)} does not match ids length {n} What it means
_validate_write_batch requires that when metadatas is provided its length matches len(ids). The check fires before any network call, raising ValueError so a truncated or extended metadata list cannot be paired with the wrong documents.
Source
Thrown at mempalace/backends/qdrant.py:231
if not any(_matches_where_document(document, clause) for clause in value or []):
return False
continue
raise UnsupportedFilterError(f"where_document operator {key!r} not supported")
return True
def _validate_write_batch(
*,
documents: list[str],
ids: list[str],
metadatas: Optional[list[dict]],
embeddings: Optional[list[list[float]]],
) -> None:
n = len(ids)
if len(documents) != n:
raise ValueError(f"documents length {len(documents)} does not match ids length {n}")
if metadatas is not None and len(metadatas) != n:
raise ValueError(f"metadatas length {len(metadatas)} does not match ids length {n}")
if embeddings is not None and len(embeddings) != n:
raise ValueError(f"embeddings length {len(embeddings)} does not match ids length {n}")
def _as_vector_array(vector: list[float]) -> np.ndarray:
arr = np.asarray(vector, dtype=np.float32)
if arr.ndim != 1 or arr.size == 0:
raise ValueError("embedding must be a non-empty 1D vector")
return arr
def _normalize_vectors(embeddings: list[list[float]]) -> tuple[list[list[float]], int]:
vectors = []
dims = set()
for embedding in embeddings:
arr = _as_vector_array(embedding)
vectors.append(arr.astype(float).tolist())
dims.add(int(arr.size))View on GitHub (pinned to 06cb6987f0)
Solutions
- Ensure one metadata entry per id; use [{}] as a placeholder when a row has no metadata (or pass None entirely).
- Construct the batch as records and derive all arrays together.
- Assert equal lengths in your ingest pipeline before calling add/upsert.
Example fix
# before
metas = [m for m in raw_metas if m] # may drop entries
col.add(ids=ids, documents=docs, metadatas=metas)
# after
metas = [m if m else {} for m in raw_metas]
col.add(ids=ids, documents=docs, metadatas=metas) Defensive patterns
Strategy: validation
Validate before calling
metas = [m or {} for m in metas] # one per id, never fewer
assert len(metas) == len(ids)
col.add(ids=ids, documents=docs, metadatas=metas) Type guard
def metadata_aligned(ids, metas) -> bool:
return metas is None or len(metas) == len(ids) Try / catch
try:
col.add(ids=ids, documents=docs, metadatas=metas)
except ValueError as e:
if "metadatas length" in str(e):
metas = (metas or []) + [{}] * (len(ids) - len(metas or []))
col.add(ids=ids, documents=docs, metadatas=metas) Prevention
- Never conditionally append metadata; use {} placeholders so lengths stay equal.
- Pass metadatas=None when none of the rows have metadata.
When it happens
Trigger: add(ids=["1","2"], documents=[d1,d2], metadatas=[m1]) — metadata built per-document but one entry dropped/skipped by a conditional.
Common situations: Metadata dicts appended inside try/except blocks that swallow failures; defaulting some rows to no metadata and building a shorter list.
Related errors
- documents length {len(documents)} does not match ids length
- embeddings length {len(embeddings)} does not match ids lengt
- metadata key {key!r} clashes with a reserved Milvus field
- {label} length {len(value)} does not match ids length {n}
- embedding must be a non-empty 1D vector
AI-assisted analysis of MemPalace/mempalace@06cb6987f0 (2026-08-15).
Data as JSON: /api/errors/badd170934f16739.
Report an issue: GitHub.