{"record":{"id":"744ee84656bff7af","repo":"dgraph-io/dgraph","slug":"left-and-right-arguments-must-match","errorCode":null,"errorMessage":"Left and right arguments must match","messagePattern":"Left and right arguments must match","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/math.go","lineNumber":33,"sourceCode":")\n\ntype mathTree struct {\n\tFn    string\n\tVar   string\n\tConst types.Val // If its a const value node.\n\tVal   *types.ShardedMap\n\tChild []*mathTree\n}\n\nvar (\n\tErrorIntOverflow     = errors.New(\"Integer overflow\")\n\tErrorFloat32Overflow = errors.New(\"Float32 overflow\")\n\tErrorDivisionByZero  = errors.New(\"Division by zero\")\n\tErrorFractionalPower = errors.New(\"Fractional power of negative number\")\n\tErrorNegativeLog     = errors.New(\"Log of negative number\")\n\tErrorNegativeRoot    = errors.New(\"Root of negative number\")\n\tErrorVectorsNotMatch = errors.New(\"The length of vectors must match\")\n\tErrorArgsDisagree    = errors.New(\"Left and right arguments must match\")\n\tErrorShouldBeVector  = errors.New(\"Type should be []float, but is not. Cannot determine type.\")\n\tErrorBadVectorMult   = errors.New(\"Cannot multiply vector by vector\")\n)\n\n// processBinary handles the binary operands like\n// +, -, *, /, %, max, min, logbase, dot\nfunc processBinary(mNode *mathTree) error {\n\taggName := mNode.Fn\n\n\tmpl := mNode.Child[0].Val\n\tmpr := mNode.Child[1].Val\n\tcl := mNode.Child[0].Const\n\tcr := mNode.Child[1].Const\n\n\tf := func(k uint64, lshard, rshard, destMapi *map[uint64]types.Val) error {\n\t\tag := aggregator{\n\t\t\tname: aggName,\n\t\t}","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/math.go#L15-L51","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure both operands are the same kind — wrap the scalar in a vector of matching length if vector math is intended","Verify the predicates/variables feeding the math block resolve to the expected type (scalar vs vector)","Split the expression: apply scalar operations in a separate math block from vector operations"],"exampleFix":"// before\nmath(embedding + 0.5) // scalar broadcast unsupported\n// after\n// store offset as a vector predicate of the same length, then:\nmath(embedding + offsetVector)","handlingStrategy":"type-guard","validationCode":"// Ensure both operands of + / - are the same kind (scalar or equal-length vectors):\nfunction operandsAgree(a, b) {\n  if (Array.isArray(a) !== Array.isArray(b)) return false;\n  if (Array.isArray(a)) return a.length === b.length;\n  return typeof a === 'number' && typeof b === 'number';\n}","typeGuard":"function isScalar(v) { return typeof v === 'number'; }\nfunction isFloatVector(v) { return Array.isArray(v) && v.every((x) => typeof x === 'number'); }","tryCatchPattern":"try {\n  const res = await dgraph.newTxn().query(queryWithMath);\n} catch (e) {\n  if (String(e).includes('arguments must match')) {\n    // inspect operand predicates: one is a vector, the other a scalar\n  } else throw e;\n}","preventionTips":["Verify predicate schemas (scalar vs []float) before writing math blocks","Never assume scalar-broadcast semantics in Dgraph math","Check that subquery/variable bindings resolve to the expected shape"],"tags":["dgraph","math","type-mismatch","vector"],"backgroundTag":"math-operand-type-mismatch","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}