chroma-core/chroma · error · ValueError

Expected SparseVector indices to be a list, got

Error message

Expected SparseVector indices to be a list, got {type(self.indices).__name__}

What it means

__post_init__ type guard on the SparseVector dataclass: rejects a SparseVector whose indices field is not a Python list (e.g., a numpy array, tuple, or generator was passed). The constructor requires plain lists so downstream serialization and length checks behave predictably.

Solutions

  1. Convert the indices with list(indices) or indices.tolist() for numpy arrays before constructing SparseVector
  2. Pass a plain Python list of ints for indices
  3. Check that positional arguments were not swapped between indices and values
Defensive patterns

Strategy: type-guard

When it happens

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

Appendix: source

Thrown at chromadb/base_types.py:35

        indices: List of dimension indices (must be non-negative integers, sorted in strictly ascending order)
        values: List of values corresponding to each index (floats)
        labels: Optional list of string labels corresponding to each index

    Note:
        - Indices must be sorted in strictly ascending order (no duplicates)
        - Indices and values must have the same length
        - If labels is provided, it must have the same length as indices and values
        - All validations are performed in __post_init__
    """

    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__}"

View on GitHub (pinned to aecdd12c8a)