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

Adds in lazy execution for Lucene kNN queries #2305

Merged
merged 1 commit into from
Dec 11, 2024

Conversation

kotwanikunal
Copy link
Member

@kotwanikunal kotwanikunal commented Dec 3, 2024

Description

  • Optimizes Lucene kNN query execution path in case of rewrites
  • The caveat here is that the rewrites would be deferred until weight creation. Any underlying changes to Lucene rewrite method would potentially be skipped with this execution mechanism.

Setup and Dataset

Flame Graph

Default 2.18 code
2 18-default-code

Patched 2.18 code
2 18-patched-code

Benchmarks

2.18 Default Code:

Metric Task Value Unit
Min Throughput prod-queries 20.93 ops/s
Mean Throughput prod-queries 63.23 ops/s
Median Throughput prod-queries 69.54 ops/s
Max Throughput prod-queries 75.17 ops/s
50th percentile latency prod-queries 10.6464 ms
90th percentile latency prod-queries 13.7257 ms
99th percentile latency prod-queries 21.3663 ms
99.9th percentile latency prod-queries 71.429 ms
100th percentile latency prod-queries 269.424 ms
50th percentile service time prod-queries 10.6464 ms
90th percentile service time prod-queries 13.7257 ms
99th percentile service time prod-queries 21.3663 ms
99.9th percentile service time prod-queries 71.429 ms
100th percentile service time prod-queries 269.424 ms
error rate prod-queries 0 %
Mean recall@k prod-queries 0.97
Mean recall@1 prod-queries 0.98

Patched new 2.18 code:

Metric Task Value Unit
Min Throughput prod-queries 75.97 ops/s
Mean Throughput prod-queries 79.29 ops/s
Median Throughput prod-queries 78.68 ops/s
Max Throughput prod-queries 83.04 ops/s
50th percentile latency prod-queries 8.66315 ms
90th percentile latency prod-queries 11.4286 ms
99th percentile latency prod-queries 21.4076 ms
99.9th percentile latency prod-queries 34.8355 ms
100th percentile latency prod-queries 53.219 ms
50th percentile service time prod-queries 8.66315 ms
90th percentile service time prod-queries 11.4286 ms
99th percentile service time prod-queries 21.4076 ms
99.9th percentile service time prod-queries 34.8355 ms
100th percentile service time prod-queries 53.219 ms
error rate prod-queries 0 %
Mean recall@k prod-queries 0.97
Mean recall@1 prod-queries 0.98

JFRs

JFR-patched-default.zip

Related Issues

Resolves #2115

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@navneet1v
Copy link
Collaborator

@kotwanikunal can you fix the CIs. Change looks good to me as it is minial in terms of changing the code and getting the best performance out of the system

@kotwanikunal
Copy link
Member Author

@kotwanikunal can you fix the CIs. Change looks good to me as it is minial in terms of changing the code and getting the best performance out of the system

@navneet1v I have updated the description with updated flame graphs and benchmarking numbers.
There are some fixes for the CI - I'll fix them shortly.

@navneet1v
Copy link
Collaborator

@kotwanikunal thanks. This p99 seems interesting. Rest all latency have decreased as expected.

@navneet1v
Copy link
Collaborator

@kotwanikunal can you please add the details like:

  1. Setup.
  2. Dataset used
    for the benchmarks

@kotwanikunal
Copy link
Member Author

@kotwanikunal can you please add the details like:

  1. Setup.
  2. Dataset used
    for the benchmarks

Added to the description.

navneet1v
navneet1v previously approved these changes Dec 9, 2024
Copy link
Collaborator

@navneet1v navneet1v left a comment

Choose a reason for hiding this comment

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

overall code looks good to me. One question I have is why we are not changing the DiversifyingChildrenByteKnnVectorQuery and DiversifyingChildrenFloatKnnVectorQuery in this PR? Is there some other PR that is taking care of this?

@kotwanikunal

@navneet1v
Copy link
Collaborator

overall code looks good to me. One question I have is why we are not changing the DiversifyingChildrenByteKnnVectorQuery and DiversifyingChildrenFloatKnnVectorQuery in this PR? Is there some other PR that is taking care of this?

@kotwanikunal

NVM, I see this PR: https://github.com/opensearch-project/k-NN/pull/2283/files#diff-d6bb9cc296becc98be3ac4bddc74c2b1520d09ff8b7d77467b3a765df17c4c11 is handling that case.

@navneet1v navneet1v added backport 2.x v2.19.0 search-improvements Enhancements Increases software capabilities beyond original client specifications labels Dec 9, 2024
Copy link
Member

@martin-gaievski martin-gaievski left a comment

Choose a reason for hiding this comment

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

Overall code looks good, added few minor comments.
Did you see impact of efficient filtering with Lucene, can you run a benchmark to check if there is an impact?

@@ -512,7 +512,7 @@ public void testDoToQuery_KnnQueryWithFilter_Lucene() throws Exception {

// Then
assertNotNull(query);
assertTrue(query.getClass().isAssignableFrom(KnnFloatVectorQuery.class));
assertTrue(query.getClass().isAssignableFrom(LuceneEngineKnnVectorQuery.class));
Copy link
Member

Choose a reason for hiding this comment

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

is there a way to check the type of the underlying lucene query, looks like this is what we're asserting in today's version? How about adding a package private getter for the lucene query, or a public method that returns the type of the query class.

Copy link
Member

@martin-gaievski martin-gaievski left a comment

Choose a reason for hiding this comment

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

Please address my comments in follow up PRs

@navneet1v navneet1v dismissed stale reviews from martin-gaievski and themself via 355a060 December 11, 2024 19:18
@navneet1v
Copy link
Collaborator

Conflicts fixed. Will wait for CI to complete

navneet1v
navneet1v previously approved these changes Dec 11, 2024
@navneet1v
Copy link
Collaborator

The BWC test: k-NN Rolling-Upgrade BWC Tests (21, ubuntu-latest, 2.19.0-SNAPSHOT, 3.0.0-SNAPSHOT) will fixed once we have code for innerhits merges and added in 2.19 snapshot.

navneet1v
navneet1v previously approved these changes Dec 11, 2024
@navneet1v navneet1v merged commit 2b9a741 into opensearch-project:main Dec 11, 2024
30 of 31 checks passed
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.x 2.x
# Navigate to the new working tree
cd .worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-2305-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 2b9a741a7cfb8c9a55c7412a6e19ea699b7a921d
# Push it to GitHub
git push --set-upstream origin backport/backport-2305-to-2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-2305-to-2.x.

opensearch-trigger-bot bot pushed a commit that referenced this pull request Dec 11, 2024
Signed-off-by: Kunal Kotwani <[email protected]>
(cherry picked from commit 2b9a741)
navneet1v pushed a commit that referenced this pull request Dec 11, 2024
Signed-off-by: Kunal Kotwani <[email protected]>
(cherry picked from commit 2b9a741)

Co-authored-by: Kunal Kotwani <[email protected]>
owenhalpert pushed a commit to owenhalpert/k-NN that referenced this pull request Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Enhancements Increases software capabilities beyond original client specifications search-improvements v2.19.0
Projects
None yet
3 participants