-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add 'profile' support for knn query on HNSW with early termination #135342
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
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
dbac429
Add 'profile' support for knn query on HNSW with early termination
tteofili ad9363b
Merge branch 'main' of github.com:elastic/elasticsearch into hnsw_et_…
tteofili c4646e5
Update docs/changelog/135342.yaml
tteofili 9bef544
retain same default
tteofili de8b16f
Merge branch 'hnsw_et_profile' of github.com:tteofili/elasticsearch i…
tteofili 29fa013
Merge branch 'main' of github.com:elastic/elasticsearch into hnsw_et_…
tteofili 2b4d005
restored canApply logic
tteofili 5acda74
[CI] Auto commit changes from spotless
53cfeb5
apply et on diversifying query too
tteofili 67af49d
Merge branch 'hnsw_et_profile' of github.com:tteofili/elasticsearch i…
tteofili 80ebe05
minor
tteofili 5ed3fe1
Merge branch 'main' of github.com:elastic/elasticsearch into hnsw_et_…
tteofili File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 135342 | ||
| summary: Add 'profile' support for knn query on HNSW with early termination | ||
| area: Vector Search | ||
| type: enhancement | ||
| issues: [] |
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
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
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
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
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
64 changes: 64 additions & 0 deletions
64
server/src/main/java/org/elasticsearch/search/vectors/PatienceCollectorManager.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.search.vectors; | ||
|
|
||
| import org.apache.lucene.index.LeafReaderContext; | ||
| import org.apache.lucene.search.HnswQueueSaturationCollector; | ||
| import org.apache.lucene.search.KnnCollector; | ||
| import org.apache.lucene.search.knn.KnnCollectorManager; | ||
| import org.apache.lucene.search.knn.KnnSearchStrategy; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class PatienceCollectorManager implements KnnCollectorManager { | ||
tteofili marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private static final double DEFAULT_SATURATION_THRESHOLD = 0.995; | ||
|
|
||
| private final KnnCollectorManager knnCollectorManager; | ||
| private final int patience; | ||
| private final double saturationThreshold; | ||
|
|
||
| PatienceCollectorManager(KnnCollectorManager knnCollectorManager, int patience, double saturationThreshold) { | ||
| this.knnCollectorManager = knnCollectorManager; | ||
| this.patience = patience; | ||
| this.saturationThreshold = saturationThreshold; | ||
| } | ||
|
|
||
| public static KnnCollectorManager wrap(KnnCollectorManager knnCollectorManager, int k) { | ||
| return new PatienceCollectorManager(knnCollectorManager, Math.max(7, (int) (k * 0.3)), DEFAULT_SATURATION_THRESHOLD); | ||
| } | ||
|
|
||
| @Override | ||
| public KnnCollector newCollector(int visitLimit, KnnSearchStrategy searchStrategy, LeafReaderContext ctx) throws IOException { | ||
| return new HnswQueueSaturationCollector( | ||
| knnCollectorManager.newCollector(visitLimit, searchStrategy, ctx), | ||
| saturationThreshold, | ||
| patience | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public KnnCollector newOptimisticCollector(int visitLimit, KnnSearchStrategy searchStrategy, LeafReaderContext ctx, int k) | ||
| throws IOException { | ||
| if (knnCollectorManager.isOptimistic()) { | ||
| return new HnswQueueSaturationCollector( | ||
| knnCollectorManager.newOptimisticCollector(visitLimit, searchStrategy, ctx, k), | ||
| saturationThreshold, | ||
| patience | ||
| ); | ||
| } else { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isOptimistic() { | ||
| return knnCollectorManager.isOptimistic(); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.