chroma-core/chroma · error · Error

Min requires at least one rank expression

Error message

Min requires at least one rank expression

What it means

Thrown by the Min rank factory (rank.ts:556) when called with zero arguments. Min builds {$min: [...]} and requires at least one rank expression. Like Max, expr.min() with no args is a no-op returning expr; the factory Min() with no operands throws.

Source

Thrown at clients/new-js/packages/chromadb/src/execution/expression/rank.ts:556

export const Exp = (input: RankInput): RankExpression =>
  requireRank(input, "Exp").exp();

export const Log = (input: RankInput): RankExpression =>
  requireRank(input, "Log").log();

export const Max = (...inputs: RankInput[]): RankExpression => {
  if (inputs.length === 0) {
    throw new Error("Max requires at least one rank expression");
  }
  const expressions = inputs.map((rank, index) =>
    requireRank(rank, `Max operand ${index}`),
  );
  return MaxRankExpression.create(expressions);
};

export const Min = (...inputs: RankInput[]): RankExpression => {
  if (inputs.length === 0) {
    throw new Error("Min requires at least one rank expression");
  }
  const expressions = inputs.map((rank, index) =>
    requireRank(rank, `Min operand ${index}`),
  );
  return MinRankExpression.create(expressions);
};

View on GitHub (pinned to aecdd12c8a)

Solutions

  1. Pass at least one operand: Min(a, b)
  2. Provide a neutral element for the empty case (e.g. a large sentinel or 0 depending on semantics): Min(...(list.length ? list : [0]))
  3. Skip the expression when the list is empty

Example fix

// before
const rank = Min(...penalties); // throws when penalties is []

// after
const rank = penalties.length ? Min(...penalties) : Val(0);
Defensive patterns

Strategy: validation

Validate before calling

const rank = penalties.length
  ? Min(...penalties)
  : Val(0);

Try / catch

try {
  const rank = Min(...penalties);
} catch (e) {
  if (e instanceof Error && e.message.includes('Min requires')) {
    return Val(0);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling Min(); spreading a dynamic list Min(...penalties) where penalties is empty — e.g. all penalty components were disabled in configuration.

Common situations: Min-over-penalty-components scoring (take the worst penalty); optional-factor pipelines where every factor is behind a flag that is off; empty arrays from upstream data queries.

Related errors


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