chroma-core/chroma · error · TypeError

$max requires a list, got {type(ranks_data).__name__}

Error message

$max requires a list, got {type(ranks_data).__name__}

What it means

$max folds a chain of pairwise maximums over rank expressions (used e.g. for clamping scores) and, like $sum/$mul, expects its payload to be a list of operand dicts. Rank.from_dict raises this TypeError when the $max payload is not a list/tuple — commonly a {'left','right'} dict copied from the $sub/$div style.

Source

Thrown at chromadb/execution/expression/operator.py:838

            child_data = data["$exp"]
            if not isinstance(child_data, dict):
                raise TypeError(
                    f"$exp requires a rank dict, got {type(child_data).__name__}"
                )
            return Rank.from_dict(child_data).exp()

        elif op == "$log":
            child_data = data["$log"]
            if not isinstance(child_data, dict):
                raise TypeError(
                    f"$log requires a rank dict, got {type(child_data).__name__}"
                )
            return Rank.from_dict(child_data).log()

        elif op == "$max":
            ranks_data = data["$max"]
            if not isinstance(ranks_data, (list, tuple)):
                raise TypeError(
                    f"$max requires a list, got {type(ranks_data).__name__}"
                )
            if len(ranks_data) < 2:
                raise ValueError(
                    f"$max requires at least 2 ranks, got {len(ranks_data)}"
                )

            ranks = [Rank.from_dict(r) for r in ranks_data]
            result = ranks[0]
            for r in ranks[1:]:
                result = result.max(r)
            return result

        elif op == "$min":
            ranks_data = data["$min"]
            if not isinstance(ranks_data, (list, tuple)):
                raise TypeError(
                    f"$min requires a list, got {type(ranks_data).__name__}"

View on GitHub (pinned to aecdd12c8a)

Solutions

  1. Use the list form: {"$max": [rank_a, {"$val": 1.0}]}
  2. Convert pair dicts: {'$max': [pair['left'], pair['right']]}
  3. Build in Python as rank.max(1.0).to_dict()
  4. Guard: isinstance(expr['$max'], (list, tuple)) before deserialization

Example fix

# before
expr = {"$max": {"left": knn_rank, "right": {"$val": 1.0}}}

# after
expr = {"$max": [knn_rank, {"$val": 1.0}]}
Defensive patterns

Strategy: validation

Validate before calling

def valid_max_expr(expr):
    return (
        isinstance(expr, dict) and set(expr) == {"$max"}
        and isinstance(expr["$max"], (list, tuple))
    )

if not valid_max_expr(rank_expr):
    raise ValueError(f"$max payload must be a list: {rank_expr!r}")

Type guard

def is_max_expr(d) -> bool:
    return (isinstance(d, dict) and set(d) == {"$max"}
            and isinstance(d["$max"], (list, tuple)))

Try / catch

try:
    rank = Rank.from_dict(rank_expr)
except (TypeError, ValueError) as e:
    raise ValueError(f"invalid rank expression {rank_expr!r}: {e}") from e

Prevention

When it happens

Trigger: Rank.from_dict({'$max': {'left': a, 'right': b}}) or {'$max': 1.0} at any depth of a rank expression tree.

Common situations: Clamping expressions (score.max(1.0)) written by hand where the author alternates between the two payload conventions; generic expression builders emitting the dict shape for all binary operators.

Related errors


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