MarkLogic 12 Product Documentation
vec.precision

vec.precision(
   vector as vec.vector?,
   [precision as Number?]
) as vec.vector

Summary

Returns a new vector which is a copy of the input vector with reduced precision. The precision reduction is achieved by clearing the bottom (32 - precision) bits of the mantissa for each dimension's float value. This can be useful for reducing storage requirements or for creating approximate vector representations.

Parameters
vector The input vector to reduce precision. Can be a vector or an empty sequence.
precision The number of mantissa bits to preserve (9-32 inclusive). Default is 16. Higher values preserve more precision. If the value is outside the valid range, throw VEC-INVALIDPRECISION.

Example

  const vec1 = vec.vector([3.14159265, 2.71828182, 1.41421356])
  vec.precision(vec1, 12)

  => "[ 3, 2.5, 1.375 ]"

Example

  const vec1 = vec.vector([3.14159265, 2.71828182, 1.41421356])
  const reduced = vec.precision(vec1)
  String(vec1) + " VS " + String(reduced)

  => "[ 3.14159, 2.71828, 1.41421 ]" VS "[ 3.14062, 2.70312, 1.41406 ]"
Powered by MarkLogic Server | Terms of Use | Privacy Policy