-
Notifications
You must be signed in to change notification settings - Fork 74
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
Conversation
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.
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 toRowTemplate
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
andend
are null-checked; consider validatingpath
,length
, andweight
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")); |
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.
Use an overload of assertEquals that includes a delta for floating-point comparisons (e.g., assertEquals(expected, actual, delta)) to avoid brittle tests.
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) { |
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.
[nitpick] Consider adding back explicit null checks or documenting that null is permitted; without precondition validation, passing null may lead to unclear NPEs downstream.
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.
9b050f8
to
83fe592
Compare
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.