Loading TOC...

MarkLogic 12 EA 1 Product Documentation
vec:subtract

vec:subtract(
   $vector1 as vec:vector,
   $vector2 as vec:vector
) as vec:vector

Summary

Returns the difference of two vectors. The vectors must be of the same dimension.

Parameters
vector1 The minuend vector.
vector2 The subtrahend vector.

Example

  xquery version "1.0-ml";
  let $vec1 := vec:vector((3.14,1.59,2.65))
  let $vec2 := vec:vector((3.58,9.79,3.23))

  return vec:subtract($vec1,$vec2);

  => [ -0.44, -8.2, -0.58 ]

Example

  xquery version "1.0-ml";

  let $vec1 := vec:vector(fn:head(fn:doc('pronethalol.json'))/data/array-node{embedding})
  let $vec2 := vec:vector(fn:head(fn:doc('cell_renewal.json'))/data/array-node{embedding})

  return vec:subtract($vec1,$vec2)

  => The difference of vectors in JSON arrays named 'embedding'
      in documents 'pronethalol.json' and 'cell_renewal.json'

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.