chroma-core/chroma · error · Error

Mul requires at least one rank expression

Error message

Mul requires at least one rank expression

What it means

Thrown by the Mul rank factory (rank.ts:521) when called with zero arguments. Mul multiplies two or more rank expressions and needs at least one operand to emit {$mul: [...]}. As with Sum, expr.multiply() with no args returns expr, but the factory Mul() with no args throws.

Source

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

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

export const Sub = (left: RankInput, right: RankInput): RankExpression =>
  new SubRankExpression(
    requireRank(left, "Sub left"),
    requireRank(right, "Sub right"),
  );

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

export const Div = (left: RankInput, right: RankInput): RankExpression =>
  new DivRankExpression(
    requireRank(left, "Div left"),
    requireRank(right, "Div right"),
  );

export const Abs = (input: RankInput): RankExpression =>
  requireRank(input, "Abs").abs();

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

View on GitHub (pinned to aecdd12c8a)

Solutions

  1. Pass at least one operand: Mul(a, b)
  2. Use the multiplicative identity for the empty case: Mul(...(factors.length ? factors : [1]))
  3. Skip the multiplication step when the factor list is empty

Example fix

// before
const rank = base.multiply(...boosts); // ok, but Mul(...boosts) with [] throws
const rank2 = Mul(...boosts); // throws when boosts is []

// after
const rank2 = Mul(...(boosts.length ? boosts : [1]));
Defensive patterns

Strategy: validation

Validate before calling

const rank = factors.length
  ? Mul(...factors)
  : Val(1); // multiplicative identity

Try / catch

try {
  const rank = Mul(...factors);
} catch (e) {
  if (e instanceof Error && e.message.includes('Mul requires')) {
    return Val(1);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling Mul(); spreading a dynamic operand list Mul(...factors) where the list is empty — e.g. every multiplicative boost was disabled or the boost array came back empty from config.

Common situations: Product-of-boosts pipelines (freshness * popularity * relevance) where all boosts are optional; multiplying user-selected factors where none are selected; refactoring that left a call site with only a spread of an optional array.

Related errors


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