Fix Range<Score> lower bound handling in vector search queries. - #4310
Open
masiljangajji wants to merge 2 commits into
Open
masiljangajji wants to merge 2 commits into
masiljangajji wants to merge 2 commits into
Conversation
JpaQueryCreator's WITHIN/NEAR keyword handling checked range.getUpperBound().isBounded() twice instead of checking both the lower and the upper bound, so a Range<Score> with only a lower bound set (e.g. Range.rightUnbounded(...)) skipped predicate generation entirely and fell through to "Near/Within keywords must be used with a Score or Range<Score> type", even though a valid Range<Score> had in fact been supplied. Ranges with only an upper bound set happened to work by accident, since that is the bound the condition was actually checking. JpaParametersParameterAccessor.doWithScore() had the same lower/upper mix-up: the branch that matches on the lower bound read the value back from getUpperBound() instead of getLowerBound(), throwing NoSuchElementException for any lower-bound-only range before JpaQueryCreator even gets to build a predicate. Both defects were introduced in the same commit, 17a5990 ("Explore returning Search Results."). Added two characterization tests to JpaQueryCreatorTests covering lower-bound-only and upper-bound-only Range<Score> queries; neither had any test coverage anywhere in the module before this change. Signed-off-by: masiljangajji <xmfpdlsj0508@gmail.com>
Range<Score> lower bound handling in vector search queries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
JpaQueryCreator'sWITHIN/NEARvector-search predicate builder andJpaParametersParameterAccessor.doWithScore()both mishandle aRange<Score>that only has a lower bound set (e.g.Range.rightUnbounded(...), a natural way to express "similarity >= X"). This affects the currently released 4.0.x and 4.1.0 lines, not justmain.Why
Both are the same class of mistake, introduced in the same commit (17a59905a7, "Explore returning Search Results."):
getUpperBound()is called wheregetLowerBound()was clearly intended.In
JpaQueryCreator, the guardrange.getUpperBound().isBounded() || range.getUpperBound().isBounded()checks the same (upper) bound twice, so a lower-bound-only range never enters the predicate-building branch and falls through toInvalidDataAccessApiUsageException("Near/Within keywords must be used with a Score or Range<Score> type")— even though a validRange<Score>was supplied.In
JpaParametersParameterAccessor.doWithScore(), the branch that matches on the lower bound reads the value back viagetUpperBound().getValue().get()instead ofgetLowerBound().getValue().get(), throwingNoSuchElementExceptionfor the same input beforeJpaQueryCreatoreven gets a chance to build a predicate.Ranges with only an upper bound set happen to work today, since that is the bound both call sites actually inspect.
Fix
JpaQueryCreator.java: checkgetLowerBound().isBounded()instead of checkinggetUpperBound().isBounded()twice.JpaParametersParameterAccessor.java: read the lower-bound branch's value fromgetLowerBound()instead ofgetUpperBound().JpaQueryCreatorTestsexercising a lower-bound-only and an upper-bound-onlyRange<Score>query end to end (JPQL rendering); this scenario had no test coverage anywhere in the module before this change.