diff --git a/lib/vector-util.js b/lib/vector-util.js index ae5619f5..66165203 100644 --- a/lib/vector-util.js +++ b/lib/vector-util.js @@ -5,6 +5,21 @@ 'use strict'; const { Buffer } = require('buffer'); +/** + * Provides functions to encode and decode vectors. + * MarkLogic 12 or higher needed. + * @namespace vectorUtil + */ + +/** + * Converts an array of vector float values into an encoded string. + * Encoding vectors before writing them to documents in MarkLogic 12 + * helps reduce the amount of disk space and memory consumed by vectors. + * @method vectorUtil#base64Encode + * @since 3.7.0 + * @param {float[]} vector - an array of float values + * @returns {string} an encoded string value. + */ const base64Encode = (vector) => { const dimensions = vector.length; const buffer = Buffer.alloc(8 + 4 * dimensions); @@ -19,6 +34,13 @@ const base64Encode = (vector) => { return buffer.toString('base64'); }; +/** + * Converts an encoded string value to an array of vectors. + * @method vectorUtil#base64Decode + * @since 3.7.0 + * @param {string} encodedVector - an encoded string value. + * @returns {float[]} an array of float values. + */ const base64Decode = (encodedVector) => { const buffer = Buffer.from(encodedVector, 'base64');