MemPalace/mempalace · error · RuntimeError

{label} count mismatch: expected {expected}, got {actual}

Error message

{label} count mismatch: expected {expected}, got {actual}

What it means

Error "{label} count mismatch: expected {expected}, got {actual}" thrown in MemPalace/mempalace.

Source

Thrown at mempalace/repair.py:312

        # chromadb 1.5.x's upsert validates that every metadatas[i] is a
        # non-empty dict (chromadb/api/types.py:validate_metadata). Drawers
        # extracted from sqlite ground truth can come back with None or {}
        # for sparse historical writes — coerce those to a sentinel so the
        # rebuild upsert can complete instead of raising ValueError ~80%
        # through a multi-hour run. See #1458 for full context.
        sanitized_metas = [
            m if (isinstance(m, dict) and len(m) > 0) else {"_repaired_empty_meta": True}
            for m in batch["metadatas"]
        ]
        all_metas.extend(sanitized_metas)
        offset += len(batch["ids"])
    return all_ids, all_docs, all_metas


def _verify_collection_count(col, expected: int, label: str) -> None:
    actual = col.count()
    if actual != expected:
        raise RuntimeError(f"{label} count mismatch: expected {expected}, got {actual}")


def _is_missing_collection_value_error(exc: ValueError) -> bool:
    message = str(exc).lower()
    return "does not exist" in message or "not found" in message


def _delete_collection_if_exists(backend, palace_path: str, collection_name: str) -> None:
    try:
        backend.delete_collection(palace_path, collection_name)
    except ValueError as exc:
        if _is_missing_collection_value_error(exc):
            return
        raise
    except (FileNotFoundError, ChromaNotFoundError):
        return

View on GitHub (pinned to 06cb6987f0)

Solutions

  1. Re-run the repair or investigate why the rebuilt count differs from the source count

When it happens

Trigger: Thrown at mempalace/repair.py:312 when the library encounters an invalid state.

Common situations: Post-rebuild verification counted a different number of rows than expected.


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