Skip to content

MLE-22471 Supporting cosine-distance and other updates from code gen #1781

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

Merged
merged 1 commit into from
Jun 16, 2025

Conversation

rjrudin
Copy link
Contributor

@rjrudin rjrudin commented Jun 16, 2025

Ran the Optic code generator, made a bunch of tweaks so as not to lose anything.

Added tests for cosineDistance, which was previously not supported. Also added tests for new variants of shortestPath.

@Copilot Copilot AI review requested due to automatic review settings June 16, 2025 19:44
Copy link

@Copilot 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 adds support for the new cosineDistance vector function, enhances existing vector operations and server calls, updates generated documentation to mark parameters as optional, and introduces overloads for the shortestPath plan operation (including weight).

  • Added cosineDistance implementation, API, and tests
  • Updated existing vector function tests for fixed output counts and introduced new vectorScore variants
  • Extended shortestPath with string and weighted overloads and migrated functional tests to RowTemplate

Reviewed Changes

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

Show a summary per file
File Description
VectorTest.java Added cosineDistance test, fixed row count, and new assertions
xs_unsignedLong.html, xs_unsignedInt.html, etc. Marked many vector/function parameters and returns as optional
VecExprImpl.java Removed explicit null checks; added cosineDistance call
PlanBuilderImpl.java Added shortestPath overloads with weight
VecExpr.java Added cosineDistance API and javadoc
TestOpticOnTriples.java Migrated shortestPath tests to RowTemplate, added weight test
Comments suppressed due to low confidence (2)

marklogic-client-api/src/main/java/com/marklogic/client/expression/VecExpr.java:90

  • Update this parameter description to reference cosine distance rather than similarity, to match the new method semantics.
* @param vector1 The vector from which to calculate the cosine similarity with vector2.  (of <a href="{@docRoot}/doc-files/types/vec_vector.html">vec:vector</a>)

marklogic-client-api/src/main/java/com/marklogic/client/impl/PlanBuilderImpl.java:2269

  • [nitpick] Only start and end are null-checked; consider validating path, length, and weight for consistency or document that null is acceptable for these parameters.
public ModifyPlan shortestPath(PlanExprCol start, PlanExprCol end, PlanExprCol path, PlanExprCol length, PlanExprCol weight) {


List<RowRecord> rows = resultRows(plan);
assertEquals(1, rows.size());
assertEquals(1.31585550308228, rows.get(0).getDouble("cosineDistance"));
Copy link
Preview

Copilot AI Jun 16, 2025

Choose a reason for hiding this comment

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

Use an overload of assertEquals that includes a delta for floating-point comparisons (e.g., assertEquals(expected, actual, delta)) to avoid brittle tests.

Suggested change
assertEquals(1.31585550308228, rows.get(0).getDouble("cosineDistance"));
assertEquals(1.31585550308228, rows.get(0).getDouble("cosineDistance"), 1e-9);

Copilot uses AI. Check for mistakes.

}


@Override
public ServerExpression cosineDistance(ServerExpression arg1, ServerExpression arg2) {
Copy link
Preview

Copilot AI Jun 16, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider adding back explicit null checks or documenting that null is permitted; without precondition validation, passing null may lead to unclear NPEs downstream.

Suggested change
public ServerExpression cosineDistance(ServerExpression arg1, ServerExpression arg2) {
public ServerExpression cosineDistance(ServerExpression arg1, ServerExpression arg2) {
if (arg1 == null) {
throw new IllegalArgumentException("Argument 'arg1' cannot be null.");
}
if (arg2 == null) {
throw new IllegalArgumentException("Argument 'arg2' cannot be null.");
}

Copilot uses AI. Check for mistakes.

Ran the Optic code generator, made a bunch of tweaks so as not to lose anything.

Added tests for cosineDistance, which was previously not supported. Also added tests for new variants of shortestPath.
@rjrudin rjrudin force-pushed the feature/22471-new-vector-functions branch from 9b050f8 to 83fe592 Compare June 16, 2025 20:53
@rjrudin rjrudin merged commit ef6ac06 into develop Jun 16, 2025
2 checks passed
@rjrudin rjrudin deleted the feature/22471-new-vector-functions branch June 16, 2025 21:58
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