Namespace: vec

planBuilder. vec

Builds expressions to call functions in the vec server library for a row pipeline.
Since:
  • 3.5.0

Methods


add(vector1, vector2) → {VecVector}

Returns the sum of two vectors. The vectors must be of the same dimension. Provides a client interface to a server function. See vec.add
Parameters:
Name Type Argument Description
vector1 VecVector <optional>
The first addend vector.
vector2 VecVector <optional>
The second addend vector.
Since:
  • 3.5.0
Returns:
Type
VecVector

base64Decode(base64Vector) → {VecVector}

Returns a vector value by decoding the base64 encoded string input. Provides a client interface to a server function. See vec.base64Decode
Parameters:
Name Type Argument Description
base64Vector XsString <optional>
The base64 binary encoded string vector to decode.
Since:
  • 3.5.0
Returns:
Type
VecVector

base64Encode(vector1) → {XsString}

Returns the base64 encoding of the vector. Useful for compressing a high-dimensional float vector represented as a string into fewer characters. Provides a client interface to a server function. See vec.base64Encode
Parameters:
Name Type Argument Description
vector1 VecVector <optional>
The vector to base64 encode.
Since:
  • 3.5.0
Returns:
Type
XsString

cosineSimilarity(vector1, vector2) → {XsDouble}

Returns the cosine similarity between two vectors. The vectors must be of the same dimension. Provides a client interface to a server function. See vec.cosineSimilarity
Parameters:
Name Type Argument Description
vector1 VecVector <optional>
The vector from which to calculate the cosine similarity with vector2.
vector2 VecVector <optional>
The vector from which to calculate the cosine similarity with vector1.
Since:
  • 3.5.0
Returns:
Type
XsDouble

dimension(vector1) → {XsUnsignedInt}

Returns the dimension of the vector passed in. Provides a client interface to a server function. See vec.dimension
Parameters:
Name Type Argument Description
vector1 VecVector <optional>
The vector to find the dimension of.
Since:
  • 3.5.0
Returns:
Type
XsUnsignedInt

dotProduct(vector1, vector2) → {XsDouble}

Returns the dot product between two vectors. The vectors must be of the same dimension. Use this function to calculate similarity between vectors if you are certain they are both of magnitude 1. Provides a client interface to a server function. See vec.dotProduct
Parameters:
Name Type Argument Description
vector1 VecVector <optional>
The vector from which to calculate the dot product with vector2.
vector2 VecVector <optional>
The vector from which to calculate the dot product with vector1.
Since:
  • 3.5.0
Returns:
Type
XsDouble

euclideanDistance(vector1, vector2) → {XsDouble}

Returns the Euclidean distance between two vectors. The vectors must be of the same dimension. Provides a client interface to a server function. See vec.euclideanDistance
Parameters:
Name Type Argument Description
vector1 VecVector <optional>
The vector from which to calculate the Euclidean distance to vector2.
vector2 VecVector <optional>
The vector from which to calculate the Euclidean distance to vector1.
Since:
  • 3.5.0
Returns:
Type
XsDouble

get(vector1, k) → {XsFloat}

Returns the element at the k-th index of the vector. Provides a client interface to a server function. See vec.get
Parameters:
Name Type Argument Description
vector1 VecVector <optional>
The vector to grab the k-th element of.
k XsUnsignedInt <optional>
The zero-based index of vector1 to return. If k is greater than the number of elements in the vector, throw VEC-OUTOFBOUNDS.
Since:
  • 3.5.0
Returns:
Type
XsFloat

magnitude(vector1) → {XsDouble}

Returns the magnitude of the vector. Provides a client interface to a server function. See vec.magnitude
Parameters:
Name Type Argument Description
vector1 VecVector <optional>
The vector to find the magnitude of.
Since:
  • 3.5.0
Returns:
Type
XsDouble

normalize(vector1) → {VecVector}

Returns the vector passed in, normalized to a length of 1. Provides a client interface to a server function. See vec.normalize
Parameters:
Name Type Argument Description
vector1 VecVector <optional>
The vector to normalize.
Since:
  • 3.5.0
Returns:
Type
VecVector

subtract(vector1, vector2) → {VecVector}

Returns the difference of two vectors. The vectors must be of the same dimension. Provides a client interface to a server function. See vec.subtract
Parameters:
Name Type Argument Description
vector1 VecVector <optional>
The minuend vector.
vector2 VecVector <optional>
The subtrahend vector.
Since:
  • 3.5.0
Returns:
Type
VecVector

subvector(vector, start, length) → {VecVector}

Returns a subvector of the input vector, starting at the specified index, with the specified length (optional). Provides a client interface to a server function. See vec.subvector
Parameters:
Name Type Argument Description
vector VecVector <optional>
The input vector.
start XsUnsignedInt <optional>
The zero-based index of the input vector from which to start (inclusive).
length XsUnsignedInt <optional>
The length of the subvector. If not provided, returns a subvector beginning from index at start to the end of the input vector. If length is greater than the number of elements left in the input vector, throw VEC-OUTOFBOUNDS.
Since:
  • 3.5.0
Returns:
Type
VecVector

vector(values) → {VecVector}

Returns a vector value. Provides a client interface to a server function. See vec.vector
Parameters:
Name Type Argument Description
values XsAnyAtomicType <optional>
The value(s) to create the vector from. Can be a sequence or json:array of integer or floating-point numbers. Also accepts a string that has the format of a JSON array of Numbers. Also accepts a string that was created by vec:base64-encode().
Since:
  • 3.5.0
Returns:
Type
VecVector

vectorScore(score, similarity, similarityWeight) → {XsUnsignedLong}

A helper function that returns a hybrid score using a cts score and a vector similarity calculation result. You can tune the effect of the vector similarity on the score using the similarityWeight option. The ideal value for similarityWeight depends on your application. Provides a client interface to a server function. See vec.vectorScore
Parameters:
Name Type Argument Description
score XsUnsignedInt <optional>
The cts:score of the matching document.
similarity XsDouble <optional>
The similarity between the vector in the matching document and the query vector. The result of a call to ovec:cosine-similarity(). In the case that the vectors are normalized, pass ovec:dot-product(). Note that vec:euclidean-distance() should not be used here.
similarityWeight XsDouble <optional>
The weight of the vector similarity on the score. The default value is 0.1. If 0.0 is passed in, vector similarity has no effect. If passed a value less than 0.0 or greater than 1.0, throw VEC-VECTORSCORE.
Since:
  • 3.5.0
Returns:
Type
XsUnsignedLong
Copyright (c) 2020 MarkLogic Corporation Documentation generated by JSDoc 4.0.0 on 2024-08-20T21:35:27-07:00 using the DocStrap template.