-
Notifications
You must be signed in to change notification settings - Fork 74
MLE-26339 Implement vec.trunc and vec.precision in Java Client API #1895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||||||
| /* | ||||||||||
| * Copyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. | ||||||||||
| * Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. | ||||||||||
| */ | ||||||||||
|
|
||||||||||
| package com.marklogic.client.impl; | ||||||||||
|
|
@@ -93,6 +93,18 @@ public ServerExpression normalize(ServerExpression vector1) { | |||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
| @Override | ||||||||||
| public ServerExpression precision(ServerExpression vector) { | ||||||||||
| return new VectorCallImpl("vec", "precision", new Object[]{ vector }); | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
| @Override | ||||||||||
| public ServerExpression precision(ServerExpression vector, ServerExpression precision) { | ||||||||||
| return new VectorCallImpl("vec", "precision", new Object[]{ vector, precision }); | ||||||||||
|
Comment on lines
+103
to
+104
|
||||||||||
| 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 }); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||||||||||||||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||||||||||||||||||
| * Copyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. | ||||||||||||||||||||||||||||||||||||||||
| * Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
| package com.marklogic.client.test.rows; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
@@ -57,6 +57,8 @@ void vectorFunctionsHappyPath() { | |||||||||||||||||||||||||||||||||||||||
| .bind(op.as("base64Encode", op.vec.base64Encode(op.col("sampleVector")))) | ||||||||||||||||||||||||||||||||||||||||
| .bind(op.as("base64Decode", op.vec.base64Decode(op.col("base64Encode")))) | ||||||||||||||||||||||||||||||||||||||||
| .bind(op.as("subVector", op.vec.subvector(op.col("sampleVector"), op.xs.integer(1), op.xs.integer(1)))) | ||||||||||||||||||||||||||||||||||||||||
| .bind(op.as("precision", op.vec.precision(op.col("sampleVector"), op.xs.unsignedInt(16)))) | ||||||||||||||||||||||||||||||||||||||||
| .bind(op.as("trunc", op.vec.trunc(op.col("sampleVector"), 1))) | ||||||||||||||||||||||||||||||||||||||||
| .bind(op.as("vectorScore", op.vec.vectorScore(op.xs.unsignedInt(1), op.xs.doubleVal(0.5)))) | ||||||||||||||||||||||||||||||||||||||||
| .bind(op.as("simpleVectorScore", op.vec.vectorScore(op.xs.unsignedInt(1), 0.5, 1))) | ||||||||||||||||||||||||||||||||||||||||
| .bind(op.as("simplestVectorScore", op.vec.vectorScore(op.xs.unsignedInt(1), 0.5))); | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -82,6 +84,8 @@ void vectorFunctionsHappyPath() { | |||||||||||||||||||||||||||||||||||||||
| assertEquals(3, ((ArrayNode) row.get("base64Decode")).size()); | ||||||||||||||||||||||||||||||||||||||||
| assertEquals(5.6, row.getDouble("get")); | ||||||||||||||||||||||||||||||||||||||||
| assertEquals(1, ((ArrayNode) row.get("subVector")).size()); | ||||||||||||||||||||||||||||||||||||||||
| assertEquals(3, ((ArrayNode) row.get("precision")).size()); | ||||||||||||||||||||||||||||||||||||||||
| assertEquals(3, ((ArrayNode) row.get("trunc")).size()); | ||||||||||||||||||||||||||||||||||||||||
| assertEquals(333333.0, row.getDouble("vectorScore")); | ||||||||||||||||||||||||||||||||||||||||
| assertEquals(666666.0, row.getDouble("simpleVectorScore")); | ||||||||||||||||||||||||||||||||||||||||
| assertEquals(333333.0, row.getDouble("simplestVectorScore")); | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -184,4 +188,70 @@ void dslAnnTopK() { | |||||||||||||||||||||||||||||||||||||||
| List<RowRecord> rows = resultRows(plan); | ||||||||||||||||||||||||||||||||||||||||
| assertEquals(2, rows.size(), "Just verifying that 'annTopK' works via the DSL and v1/rows."); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||
| void precision() { | ||||||||||||||||||||||||||||||||||||||||
| // Test vec.precision with default precision (16 bits) | ||||||||||||||||||||||||||||||||||||||||
| PlanBuilder.ModifyPlan plan = op.fromView("vectors", "persons") | ||||||||||||||||||||||||||||||||||||||||
| .limit(1) | ||||||||||||||||||||||||||||||||||||||||
| .bind(op.as("testVector", op.vec.vector(op.xs.doubleSeq(3.14159265, 2.71828182, 1.41421356)))) | ||||||||||||||||||||||||||||||||||||||||
| .bind(op.as("precisionDefault", op.vec.precision(op.col("testVector")))) | ||||||||||||||||||||||||||||||||||||||||
| .bind(op.as("precision10", op.vec.precision(op.col("testVector"), op.xs.unsignedInt(10)))); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| List<RowRecord> rows = resultRows(plan); | ||||||||||||||||||||||||||||||||||||||||
| assertEquals(1, rows.size()); | ||||||||||||||||||||||||||||||||||||||||
| RowRecord row = rows.get(0); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| // Verify that precision returns a vector | ||||||||||||||||||||||||||||||||||||||||
| ArrayNode precisionDefault = (ArrayNode) row.get("precisionDefault"); | ||||||||||||||||||||||||||||||||||||||||
| assertNotNull(precisionDefault); | ||||||||||||||||||||||||||||||||||||||||
| assertEquals(3, precisionDefault.size()); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| // Verify precision with 10 bits - should truncate values | ||||||||||||||||||||||||||||||||||||||||
| ArrayNode precision10 = (ArrayNode) row.get("precision10"); | ||||||||||||||||||||||||||||||||||||||||
| assertNotNull(precision10); | ||||||||||||||||||||||||||||||||||||||||
| assertEquals(3, precision10.size()); | ||||||||||||||||||||||||||||||||||||||||
| 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"); | ||||||||||||||||||||||||||||||||||||||||
|
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"); | |
| // 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"); |
There was a problem hiding this comment.
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.