Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/vector-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type annotation 'float[]' is not valid JSDoc syntax. Use 'number[]' instead, as JavaScript uses the number type for all numeric values including floats.

Suggested change
* @param {float[]} vector - an array of float values
* @param {number[]} vector - an array of float values

Copilot uses AI. Check for mistakes.
* @returns {string} an encoded string value.
*/
const base64Encode = (vector) => {
const dimensions = vector.length;
const buffer = Buffer.alloc(8 + 4 * dimensions);
Expand All @@ -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.
Copy link

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type annotation 'float[]' is not valid JSDoc syntax. Use 'number[]' instead, as JavaScript uses the number type for all numeric values including floats.

Suggested change
* @returns {float[]} an array of float values.
* @returns {number[]} an array of float values.

Copilot uses AI. Check for mistakes.
*/
const base64Decode = (encodedVector) => {

const buffer = Buffer.from(encodedVector, 'base64');
Expand Down