chroma-core/chroma · error · ValueError

SparseVector indices and values must have the same length…

Error message

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

What it means

__post_init__ structural check on SparseVector: indices and values must be parallel arrays of equal length (one value per index). This error fires when the two lists diverge in length, meaning the sparse vector is malformed and some indices would have no value or vice versa.

Solutions

  1. Ensure each index has exactly one corresponding value
  2. Rebuild the sparse vector from its source so indices and values are derived from the same iteration
  3. Check for off-by-one slicing or partial updates of one list but not the other
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at chromadb/base_types.py:45 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/7d6165d7247d14ce. Report an issue: GitHub.

Appendix: source

Thrown at chromadb/base_types.py:45

    indices: List[int]
    values: List[float]
    labels: Optional[List[str]] = None

    def __post_init__(self) -> None:
        """Validate sparse vector structure."""
        if not isinstance(self.indices, list):
            raise ValueError(
                f"Expected SparseVector indices to be a list, got {type(self.indices).__name__}"
            )

        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(

View on GitHub (pinned to aecdd12c8a)