chroma-core/chroma · error · TypeError

rank must be a Rank object, dict, or None, got

Error message

rank must be a Rank object, dict, or None, got {type(rank).__name__}

What it means

Raised by the plan constructor when the rank argument is not a Rank object, a dict (convertible via Rank.from_dict), or None — e.g. a raw number was passed where a rank specification (or {"$val": n} dict for a constant rank) is required.

Solutions

  1. Pass a Rank object, a rank dict, or None
  2. For a constant rank value use {"$val": number} instead of a bare number
  3. Wrap a KNN expression dict, e.g. {"$knn": {...}}
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at chromadb/execution/expression/plan.py:114 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/974834d3dc318c5e. Report an issue: GitHub.

Appendix: source

Thrown at chromadb/execution/expression/plan.py:114

            self._where = None
        elif isinstance(where, Where):
            self._where = where
        elif isinstance(where, dict):
            self._where = Where.from_dict(where)
        else:
            raise TypeError(
                f"where must be a Where object, dict, or None, got {type(where).__name__}"
            )

        # Handle rank parameter
        if rank is None:
            self._rank = None
        elif isinstance(rank, Rank):
            self._rank = rank
        elif isinstance(rank, dict):
            self._rank = Rank.from_dict(rank)
        else:
            raise TypeError(
                f"rank must be a Rank object, dict, or None, got {type(rank).__name__}"
            )

        # Handle group_by parameter
        if group_by is None:
            self._group_by = GroupBy()
        elif isinstance(group_by, GroupBy):
            self._group_by = group_by
        elif isinstance(group_by, dict):
            self._group_by = GroupBy.from_dict(group_by)
        else:
            raise TypeError(
                f"group_by must be a GroupBy object, dict, or None, got {type(group_by).__name__}"
            )

        # Handle limit parameter
        if limit is None:
            self._limit = Limit()

View on GitHub (pinned to aecdd12c8a)