dgraph-io/dgraph · error

Left and right arguments must match

Error message

Left and right arguments must match

What it means

ErrorArgsDisagree is a sentinel error in Dgraph's math package returned by applyAdd and applySub when the two arguments are of incompatible kinds — e.g. adding/subtracting a scalar to a vector, or mixing types that cannot be combined element-wise. Both sides must agree in type (scalar+scalar or vector+vector of same length).

Source

Thrown at query/math.go:33

)

type mathTree struct {
	Fn    string
	Var   string
	Const types.Val // If its a const value node.
	Val   *types.ShardedMap
	Child []*mathTree
}

var (
	ErrorIntOverflow     = errors.New("Integer overflow")
	ErrorFloat32Overflow = errors.New("Float32 overflow")
	ErrorDivisionByZero  = errors.New("Division by zero")
	ErrorFractionalPower = errors.New("Fractional power of negative number")
	ErrorNegativeLog     = errors.New("Log of negative number")
	ErrorNegativeRoot    = errors.New("Root of negative number")
	ErrorVectorsNotMatch = errors.New("The length of vectors must match")
	ErrorArgsDisagree    = errors.New("Left and right arguments must match")
	ErrorShouldBeVector  = errors.New("Type should be []float, but is not. Cannot determine type.")
	ErrorBadVectorMult   = errors.New("Cannot multiply vector by vector")
)

// processBinary handles the binary operands like
// +, -, *, /, %, max, min, logbase, dot
func processBinary(mNode *mathTree) error {
	aggName := mNode.Fn

	mpl := mNode.Child[0].Val
	mpr := mNode.Child[1].Val
	cl := mNode.Child[0].Const
	cr := mNode.Child[1].Const

	f := func(k uint64, lshard, rshard, destMapi *map[uint64]types.Val) error {
		ag := aggregator{
			name: aggName,
		}

View on GitHub (pinned to 759e242be6)

Solutions

  1. Ensure both operands are the same kind — wrap the scalar in a vector of matching length if vector math is intended
  2. Verify the predicates/variables feeding the math block resolve to the expected type (scalar vs vector)
  3. Split the expression: apply scalar operations in a separate math block from vector operations

Example fix

// before
math(embedding + 0.5) // scalar broadcast unsupported
// after
// store offset as a vector predicate of the same length, then:
math(embedding + offsetVector)
Defensive patterns

Strategy: type-guard

Validate before calling

// Ensure both operands of + / - are the same kind (scalar or equal-length vectors):
function operandsAgree(a, b) {
  if (Array.isArray(a) !== Array.isArray(b)) return false;
  if (Array.isArray(a)) return a.length === b.length;
  return typeof a === 'number' && typeof b === 'number';
}

Type guard

function isScalar(v) { return typeof v === 'number'; }
function isFloatVector(v) { return Array.isArray(v) && v.every((x) => typeof x === 'number'); }

Try / catch

try {
  const res = await dgraph.newTxn().query(queryWithMath);
} catch (e) {
  if (String(e).includes('arguments must match')) {
    // inspect operand predicates: one is a vector, the other a scalar
  } else throw e;
}

Prevention

When it happens

Trigger: math(a + b) or math(a - b) where one side is a scalar (int/float) and the other a []float vector, or other type-mismatched operand pairs; returned by applyAdd and applySub.

Common situations: Adding a constant offset to an embedding vector expecting broadcast semantics (not supported); a predicate unexpectedly stored as vector when assumed scalar; variable/subquery producing a different shape than expected.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/744ee84656bff7af. Report an issue: GitHub.