Skip to content

Conversation

@anu3990
Copy link
Contributor

@anu3990 anu3990 commented Jul 16, 2025

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements vector base64 encoding and decoding functionality for the MarkLogic Node.js client. The changes add client-side utilities to convert between floating-point vector arrays and base64-encoded binary representations, enabling interoperability with MarkLogic's server-side vector functions.

  • Added vector-util.js library with base64Encode and base64Decode functions
  • Implemented comprehensive test suite covering client-side encoding/decoding and cross-compatibility with server-side functions
  • Added validation for unsupported vector versions in the decode function

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 10 comments.

File Description
lib/vector-util.js Core implementation of vector base64 encoding/decoding utilities with buffer manipulation
test-basic/vector-util-test.js Complete test suite validating encoding/decoding accuracy and server-client interoperability

const input = 'AAAAAAMAAADD9UhAH4XLP5qZKUA=';
const decoded = vectorUtil.base64Decode(input);
try {
assert(Object.getPrototypeOf(decoded) == Array.prototype);
Copy link

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

Use Array.isArray(decoded) instead of Object.getPrototypeOf(decoded) == Array.prototype for more reliable array type checking.

Suggested change
assert(Object.getPrototypeOf(decoded) == Array.prototype);
assert(Array.isArray(decoded));

Copilot uses AI. Check for mistakes.
const input = response.rows[0].t.value;
const decoded = vectorUtil.base64Decode(input);
assert(input =='AAAAAAEAAABvEgM7');
assert(Object.getPrototypeOf(decoded) == Array.prototype);
Copy link

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

Use Array.isArray(decoded) instead of Object.getPrototypeOf(decoded) == Array.prototype for more reliable array type checking.

Suggested change
assert(Object.getPrototypeOf(decoded) == Array.prototype);
assert(Array.isArray(decoded));

Copilot uses AI. Check for mistakes.
.then(function(response) {
const input = response.rows[0].t.value;
const decoded = vectorUtil.base64Decode(input);
assert(input =='AAAAAAEAAABvEgM7');
Copy link

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

Use assert.strictEqual() instead of loose equality comparison for more precise testing.

Suggested change
assert(input =='AAAAAAEAAABvEgM7');
assert.strictEqual(input, 'AAAAAAEAAABvEgM7');

Copilot uses AI. Check for mistakes.
Comment on lines 50 to 53
assert(Object.getPrototypeOf(decoded) == Array.prototype);
assert(decoded[0] == 3.140000104904175);
assert(decoded[1] == 1.590000033378601);
assert(decoded[2] == 2.6500000953674316);
Copy link

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

Use assert.strictEqual() instead of loose equality comparison for more precise testing.

Suggested change
assert(Object.getPrototypeOf(decoded) == Array.prototype);
assert(decoded[0] == 3.140000104904175);
assert(decoded[1] == 1.590000033378601);
assert(decoded[2] == 2.6500000953674316);
assert(Object.getPrototypeOf(decoded) === Array.prototype);
assert(Math.abs(decoded[0] - 3.140000104904175) < delta, 'Value mismatch for decoded[0]');
assert(Math.abs(decoded[1] - 1.590000033378601) < delta, 'Value mismatch for decoded[1]');
assert(Math.abs(decoded[2] - 2.6500000953674316) < delta, 'Value mismatch for decoded[2]');

Copilot uses AI. Check for mistakes.
Comment on lines 51 to 53
assert(decoded[0] == 3.140000104904175);
assert(decoded[1] == 1.590000033378601);
assert(decoded[2] == 2.6500000953674316);
Copy link

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

Use assert.strictEqual() instead of loose equality comparison for more precise testing.

Suggested change
assert(decoded[0] == 3.140000104904175);
assert(decoded[1] == 1.590000033378601);
assert(decoded[2] == 2.6500000953674316);
assert.strictEqual(decoded[0], 3.140000104904175);
assert.strictEqual(decoded[1], 1.590000033378601);
assert.strictEqual(decoded[2], 2.6500000953674316);

Copilot uses AI. Check for mistakes.
assert(Object.getPrototypeOf(decoded) == Array.prototype);
assert(decoded[0] == 3.140000104904175);
assert(decoded[1] == 1.590000033378601);
assert(decoded[2] == 2.6500000953674316);
Copy link

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

Use assert.strictEqual() instead of loose equality comparison for more precise testing.

Suggested change
assert(decoded[2] == 2.6500000953674316);
assert(Math.abs(decoded[2] - 2.6500000953674316) < delta, 'Value mismatch for decoded[2]');

Copilot uses AI. Check for mistakes.
Comment on lines 70 to 71
assert(Object.getPrototypeOf(decoded) == Array.prototype);
assert(decoded[0] == 0.0020000000949949026);
Copy link

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

Use assert.strictEqual() instead of loose equality comparison for more precise testing.

Suggested change
assert(Object.getPrototypeOf(decoded) == Array.prototype);
assert(decoded[0] == 0.0020000000949949026);
assert(Object.getPrototypeOf(decoded) === Array.prototype);
assert(Math.abs(decoded[0] - 0.0020000000949949026) < delta, 'Value mismatch');

Copilot uses AI. Check for mistakes.
const input = vectorUtil.base64Encode(vector);
const vectorString = '[ '+vector[0].toString()+', '+vector[1].toString()+', '+vector[2].toString()+' ]';
dbWriter.eval(`vec.base64Decode('${input}')`).result(res=>{
assert(res[0].value == vectorString);
Copy link

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

Use assert.strictEqual() instead of loose equality comparison for more precise testing.

Suggested change
assert(res[0].value == vectorString);
assert.strictEqual(res[0].value, vectorString);

Copilot uses AI. Check for mistakes.
'use strict';
const { Buffer } = require('buffer');

const base64Encode = (vector) => {

This comment was marked as off-topic.

};

const base64Decode = (encodedVector) => {

This comment was marked as off-topic.

Copy link
Contributor

@rjrudin rjrudin left a comment

Choose a reason for hiding this comment

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

Looks good, though I think all the Copilot suggestions are good ones, especially the ones to assert using "strict equals".

@anu3990 anu3990 merged commit c75be94 into marklogic:develop Jul 17, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants