Skip to content

MLE-26339 Implement vec.trunc and vec.precision in Java Client API#1895

Merged
stevebio merged 1 commit intodevelopfrom
feature/MLE-26339-implement-vec-precision-trunc
Feb 6, 2026
Merged

MLE-26339 Implement vec.trunc and vec.precision in Java Client API#1895
stevebio merged 1 commit intodevelopfrom
feature/MLE-26339-implement-vec-precision-trunc

Conversation

@stevebio
Copy link

@stevebio stevebio commented Feb 6, 2026

MLE-26339 Implement vec.trunc and vec.precision in Java Client API.

@github-actions
Copy link

github-actions bot commented Feb 6, 2026

Copyright Validation Results
Total: 3 | Passed: 3 | Failed: 0 | Skipped: 0 | at: 2026-02-06 03:21:38 UTC | commit: 92943f6

✅ Valid Files

  • marklogic-client-api/src/main/java/com/marklogic/client/expression/VecExpr.java
  • marklogic-client-api/src/main/java/com/marklogic/client/impl/VecExprImpl.java
  • marklogic-client-api/src/test/java/com/marklogic/client/test/rows/VectorTest.java

✅ All files have valid copyright headers!

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.

LGTM!

@stevebio stevebio marked this pull request as ready for review February 6, 2026 16:16
@stevebio stevebio requested a review from BillFarber as a code owner February 6, 2026 16:16
Copilot AI review requested due to automatic review settings February 6, 2026 16:16
@stevebio stevebio merged commit 455048a into develop Feb 6, 2026
4 checks passed
@stevebio stevebio deleted the feature/MLE-26339-implement-vec-precision-trunc branch February 6, 2026 16:17
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

Implements support for vec:precision and vec:trunc in the Java Client API’s vector expression DSL, along with associated tests.

Changes:

  • Added precision(...) and trunc(...) methods to VecExpr and implemented them in VecExprImpl.
  • Extended VectorTest with new test cases covering vec.precision and vec.trunc.
  • Updated existing “happy path” vector function test to include the new functions.

Reviewed changes

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

File Description
marklogic-client-api/src/test/java/com/marklogic/client/test/rows/VectorTest.java Adds/extends tests exercising vec.precision and vec.trunc via the rows DSL.
marklogic-client-api/src/main/java/com/marklogic/client/impl/VecExprImpl.java Implements new DSL methods so they emit vec:precision and vec:trunc calls.
marklogic-client-api/src/main/java/com/marklogic/client/expression/VecExpr.java Adds public API surface + Javadoc for precision and trunc.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +214 to +216
assertEquals(3, precision10.get(0).asInt(), "First element should be truncated to 3");
assertEquals(2, precision10.get(1).asInt(), "Second element should be truncated to 2");
assertEquals(1, precision10.get(2).asInt(), "Third element should be truncated to 1");
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

These assertions don’t actually verify reduced precision behavior; they only check the integer part (which would be the same even if vec:precision were a no-op). Consider asserting on the returned floating-point values (via asDouble() with an expected tolerance) and/or asserting that precision10 differs from the original input (or from precisionDefault) by a measurable amount.

Suggested change
assertEquals(3, precision10.get(0).asInt(), "First element should be truncated to 3");
assertEquals(2, precision10.get(1).asInt(), "Second element should be truncated to 2");
assertEquals(1, precision10.get(2).asInt(), "Third element should be truncated to 1");
// Check floating-point values with a tolerance instead of only integer parts
assertEquals(3.0, precision10.get(0).asDouble(), 0.001, "First element should be truncated near 3.0");
assertEquals(2.0, precision10.get(1).asDouble(), 0.001, "Second element should be truncated near 2.0");
assertEquals(1.0, precision10.get(2).asDouble(), 0.001, "Third element should be truncated near 1.0");
// Verify that reduced-precision values differ from default-precision values
double default0 = precisionDefault.get(0).asDouble();
double default1 = precisionDefault.get(1).asDouble();
double default2 = precisionDefault.get(2).asDouble();
double p10_0 = precision10.get(0).asDouble();
double p10_1 = precision10.get(1).asDouble();
double p10_2 = precision10.get(2).asDouble();
assertNotEquals(default0, p10_0, "Reduced precision should differ from default precision for first element");
assertNotEquals(default1, p10_1, "Reduced precision should differ from default precision for second element");
assertNotEquals(default2, p10_2, "Reduced precision should differ from default precision for third element");

Copilot uses AI. Check for mistakes.
Comment on lines +103 to +104
public ServerExpression precision(ServerExpression vector, ServerExpression precision) {
return new VectorCallImpl("vec", "precision", new Object[]{ vector, precision });
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

The parameter name precision is easy to confuse with the method name and with the concept of “precision” more generally. Consider renaming the parameter to something more specific like precisionBits (or whatever term aligns with server docs) to improve readability.

Suggested change
public ServerExpression precision(ServerExpression vector, ServerExpression precision) {
return new VectorCallImpl("vec", "precision", new Object[]{ vector, precision });
public ServerExpression precision(ServerExpression vector, ServerExpression precisionBits) {
return new VectorCallImpl("vec", "precision", new Object[]{ vector, precisionBits });

Copilot uses AI. Check for mistakes.
Comment on lines +154 to +160
/**
* 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.
*
* <a name="ml-server-type-precision"></a>

* <p>
* Provides a client interface to the <a href="http://docs.marklogic.com/vec:precision" target="mlserverdoc">vec:precision</a> server function.
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

The new Javadocs are hard to read due to very long lines, duplicated text across overloads, and some inconsistent blank-line formatting (e.g., the whitespace-only line after the <a name=...> anchor). Consider wrapping lines, removing/avoiding whitespace-only lines, and factoring shared wording into one place (e.g., keep a shorter overload doc that references the main one) to keep the public API docs consistent and maintainable.

Copilot uses AI. Check for mistakes.
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