Skip to content
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

feat: vector search with distance range #3326

Merged
merged 5 commits into from
Jan 3, 2025

Conversation

BubbleCal
Copy link
Contributor

No description provided.

@github-actions github-actions bot added enhancement New feature or request java labels Jan 2, 2025
Signed-off-by: BubbleCal <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Jan 2, 2025

Codecov Report

Attention: Patch coverage is 89.53975% with 25 lines in your changes missing coverage. Please review.

Project coverage is 78.97%. Comparing base (2092808) to head (7d3ad66).
Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
rust/lance-index/src/vector/flat/index.rs 77.77% 8 Missing ⚠️
rust/lance/src/dataset/scanner.rs 84.00% 0 Missing and 8 partials ⚠️
rust/lance/src/index/vector/pq.rs 81.81% 0 Missing and 6 partials ⚠️
java/core/lance-jni/src/utils.rs 0.00% 2 Missing ⚠️
rust/lance/src/index/vector/ivf/v2.rs 99.12% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3326      +/-   ##
==========================================
- Coverage   79.01%   78.97%   -0.04%     
==========================================
  Files         246      246              
  Lines       87628    88095     +467     
  Branches    87628    88095     +467     
==========================================
+ Hits        69238    69572     +334     
- Misses      15523    15631     +108     
- Partials     2867     2892      +25     
Flag Coverage Δ
unittests 78.97% <89.53%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@BubbleCal BubbleCal marked this pull request as ready for review January 2, 2025 10:58
@@ -88,6 +94,8 @@ impl IvfSubIndex for FlatIndex {
dist: OrderedFloat(dist),
})
.sorted_unstable()
.skip_while(|r| params.lower_bound.map_or(false, |lb| r.dist.0 < lb))
Copy link
Contributor

Choose a reason for hiding this comment

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

should we do skip / take before sort?

Also giving most the case, low/high bounds are usually not set. Should we only run those two steps if low/high bounds are set, each of them is a O(n) operation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

filter before sort would evaluate the prediction on all results then it's O(n) as well.

skip_while and take_while is lazy, so they would stop once take gets enough k results.
we can optimize this by binary search.

Copy link
Contributor

Choose a reason for hiding this comment

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

There are two cases:

  1. without lower_bound. /upper bound, sorted_unstable is O(nlogn), where n = num of rows in each partition.

  2. with lower_bound / upper bound, sorted_unstable complexity becomes O(n_2 * log(n_2)) where n_2 is the filtered results?

The N in time complexity might be significantly different.

Copy link
Contributor

Choose a reason for hiding this comment

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

Non the less, can we just run some benchmarks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Signed-off-by: BubbleCal <[email protected]>
@BubbleCal BubbleCal requested a review from eddyxu January 3, 2025 05:21
Signed-off-by: BubbleCal <[email protected]>
Copy link
Contributor

@eddyxu eddyxu left a comment

Choose a reason for hiding this comment

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

LGTM. could you make a follow up ticket to expose this in lancedb and make sure we have docs.

@BubbleCal
Copy link
Contributor Author

LGTM. could you make a follow up ticket to expose this in lancedb and make sure we have docs.

#3331

@BubbleCal BubbleCal merged commit 39f12dc into lancedb:main Jan 3, 2025
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request java
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants