chroma-core/chroma · error · ValueError

SparseVector labels must have the same length as indices…

Error message

SparseVector labels must have the same length as indices and values, got {len(self.labels)} labels, {len(self.indices)} indices

What it means

__post_init__ structural check on SparseVector: when labels is supplied, it must be parallel to indices and values, so its length must equal len(indices). Fires when a shorter or longer label list is passed, which would leave some dimensions unlabeled or labels unmatched.

Solutions

  1. Provide exactly one label per index/value
  2. Derive labels from the same source as indices to keep lengths in sync
  3. Omit labels if per-dimension labels are not needed
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at chromadb/base_types.py:56 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16). Data as JSON: /api/errors/fba1c826e9e2ffb1. Report an issue: GitHub.

Appendix: source

Thrown at chromadb/base_types.py:56

        if not isinstance(self.values, list):
            raise ValueError(
                f"Expected SparseVector values to be a list, got {type(self.values).__name__}"
            )

        if len(self.indices) != len(self.values):
            raise ValueError(
                f"SparseVector indices and values must have the same length, "
                f"got {len(self.indices)} indices and {len(self.values)} values"
            )

        if self.labels is not None:
            if not isinstance(self.labels, list):
                raise ValueError(
                    f"Expected SparseVector labels to be a list, got {type(self.labels).__name__}"
                )
            if len(self.labels) != len(self.indices):
                raise ValueError(
                    f"SparseVector labels must have the same length as indices and values, "
                    f"got {len(self.labels)} labels, {len(self.indices)} indices"
                )

        for i, idx in enumerate(self.indices):
            if not isinstance(idx, int):
                raise ValueError(
                    f"SparseVector indices must be integers, got {type(idx).__name__} at position {i}"
                )
            if idx < 0:
                raise ValueError(
                    f"SparseVector indices must be non-negative, got {idx} at position {i}"
                )

        for i, val in enumerate(self.values):
            if not isinstance(val, (int, float)):
                raise ValueError(
                    f"SparseVector values must be numbers, got {type(val).__name__} at position {i}"

View on GitHub (pinned to aecdd12c8a)