-
Notifications
You must be signed in to change notification settings - Fork 408
two queue filtered search with max effort #929
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
Open
hailangx
wants to merge
25
commits into
main
Choose a base branch
from
haixu/two-queue-filtered-search
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
e093790
two queue search
02c6cbd
Merge branch 'main' of https://github.com/microsoft/DiskANN into haix…
5f2e5aa
use native heap for explore queue
0a82a37
fix
e554450
RESULT_SIZE_FACTOR
0b30d3f
Merge branch 'main' of https://github.com/microsoft/DiskANN into haix…
9a57a7f
fix feature gate clippy
1bcc9dd
fix doc
fffd119
Update diskann-garnet/src/lib.rs
hailangx e1026a0
Update diskann-garnet/src/lib.rs
hailangx 6beff12
Update diskann-benchmark/src/backend/index/spherical.rs
hailangx ecec081
fix typo
1ad7e2e
add test
aa88158
Move k-means implementation from diskann-providers to diskann-disk (#…
Copilot cbfe112
Inline minmax distance evaluations (#935)
arkrishn94 1e9766c
Use `rust-toolchain.toml` in CI (#934)
hildebrandmw 6b931fb
Add a globally blocking CI gate. (#932)
hildebrandmw a2a81c8
Remove `utils/math_util.rs` from `diskann-providers` (#921)
Copilot afab226
Bump rand from 0.9.2 to 0.9.3 (#945)
dependabot[bot] e027618
Remove OPQ and friends (#947)
arkrishn94 4c4be19
Migrate test_flaky_consolidate from diskann_providers to diskann (#942)
JordanMaples 66dc734
Remove GraphDataType from diskann-providers (#950)
wuw92 1024e17
Merge https://github.com/microsoft/DiskANN into haixu/two-queue-filte…
a2bb122
fix
0cbda48
Merge branch 'main' into haixu/two-queue-filtered-search
hailangx 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
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,142 @@ | ||
| /* | ||
| * Copyright (c) Microsoft Corporation. | ||
| * Licensed under the MIT license. | ||
| */ | ||
|
|
||
| use std::sync::Arc; | ||
|
|
||
| use diskann::{ | ||
| ANNResult, | ||
| graph::{self, glue, search::TwoQueueSearch}, | ||
| provider, | ||
| }; | ||
| use diskann_utils::{future::AsyncFriendly, views::Matrix}; | ||
|
|
||
| use crate::search::{self, Search, graph::Strategy}; | ||
|
|
||
| /// A built-in helper for benchmarking filtered K-nearest neighbors search | ||
| /// using the two-queue search method. | ||
| /// | ||
| /// This is intended to be used in conjunction with [`search::search`] or [`search::search_all`] | ||
| /// and provides some basic additional metrics for the latter. Result aggregation for | ||
| /// [`search::search_all`] is provided by the [`search::graph::knn::Aggregator`] type (same | ||
| /// aggregator as [`search::graph::knn::KNN`]). | ||
| /// | ||
| /// The provided implementation of [`Search`] accepts [`graph::search::Knn`] | ||
| /// and returns [`search::graph::knn::Metrics`] as additional output. | ||
| #[derive(Debug)] | ||
| pub struct TwoQueue<DP, T, S> | ||
| where | ||
| DP: provider::DataProvider, | ||
| { | ||
| index: Arc<graph::DiskANNIndex<DP>>, | ||
| queries: Arc<Matrix<T>>, | ||
| strategy: Strategy<S>, | ||
| labels: Arc<[Arc<dyn graph::index::QueryLabelProvider<DP::InternalId>>]>, | ||
| max_candidates: usize, | ||
| result_size_factor: usize, | ||
| } | ||
|
|
||
| impl<DP, T, S> TwoQueue<DP, T, S> | ||
| where | ||
| DP: provider::DataProvider, | ||
| { | ||
| /// Construct a new [`TwoQueue`] searcher. | ||
| /// | ||
| /// If `strategy` is one of the container variants of [`Strategy`], its length | ||
| /// must match the number of rows in `queries`. If this is the case, then the | ||
| /// strategies will have a querywise correspondence (see [`search::SearchResults`]) | ||
| /// with the query matrix. | ||
| /// | ||
| /// Additionally, the length of `labels` must match the number of rows in `queries` | ||
| /// and will be used in querywise correspondence with `queries`. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns an error under the following conditions. | ||
| /// | ||
| /// 1. The number of elements in `strategy` is not compatible with the number of rows in | ||
| /// `queries`. | ||
| /// | ||
| /// 2. The number of label providers in `labels` is not equal to the number of rows in | ||
| /// `queries`. | ||
| pub fn new( | ||
| index: Arc<graph::DiskANNIndex<DP>>, | ||
| queries: Arc<Matrix<T>>, | ||
| strategy: Strategy<S>, | ||
| labels: Arc<[Arc<dyn graph::index::QueryLabelProvider<DP::InternalId>>]>, | ||
| max_candidates: usize, | ||
| result_size_factor: usize, | ||
| ) -> anyhow::Result<Arc<Self>> { | ||
| strategy.length_compatible(queries.nrows())?; | ||
|
|
||
| if labels.len() != queries.nrows() { | ||
| Err(anyhow::anyhow!( | ||
| "Number of label providers ({}) must be equal to the number of queries ({})", | ||
| labels.len(), | ||
| queries.nrows() | ||
| )) | ||
| } else { | ||
| Ok(Arc::new(Self { | ||
| index, | ||
| queries, | ||
| strategy, | ||
| labels, | ||
| max_candidates, | ||
| result_size_factor, | ||
| })) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<DP, T, S> Search for TwoQueue<DP, T, S> | ||
| where | ||
| DP: provider::DataProvider<Context: Default, ExternalId: search::Id>, | ||
| S: for<'a> glue::DefaultSearchStrategy<DP, &'a [T], DP::ExternalId> + Clone + AsyncFriendly, | ||
| T: AsyncFriendly + Clone, | ||
| { | ||
| type Id = DP::ExternalId; | ||
| type Parameters = graph::search::Knn; | ||
| type Output = super::knn::Metrics; | ||
|
|
||
| fn num_queries(&self) -> usize { | ||
| self.queries.nrows() | ||
| } | ||
|
|
||
| fn id_count(&self, parameters: &Self::Parameters) -> search::IdCount { | ||
| search::IdCount::Fixed(parameters.k_value()) | ||
| } | ||
|
|
||
| async fn search<O>( | ||
| &self, | ||
| parameters: &Self::Parameters, | ||
| buffer: &mut O, | ||
| index: usize, | ||
| ) -> ANNResult<Self::Output> | ||
| where | ||
| O: graph::SearchOutputBuffer<DP::ExternalId> + Send, | ||
| { | ||
| let context = DP::Context::default(); | ||
| let two_queue_search = TwoQueueSearch::new( | ||
| *parameters, | ||
| &*self.labels[index], | ||
| self.max_candidates, | ||
| self.result_size_factor, | ||
| ); | ||
| let result = self | ||
| .index | ||
| .search( | ||
| two_queue_search, | ||
| self.strategy.get(index)?, | ||
| &context, | ||
| self.queries.row(index), | ||
| buffer, | ||
| ) | ||
| .await?; | ||
|
|
||
| Ok(super::knn::Metrics { | ||
| comparisons: result.stats.cmps, | ||
| hops: result.stats.hops, | ||
| }) | ||
| } | ||
| } |
50 changes: 50 additions & 0 deletions
50
diskann-benchmark/example/async-two-queue-filter-ground-truth-small.json
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,50 @@ | ||
| { | ||
| "search_directories": [ | ||
| "test_data/disk_index_search" | ||
| ], | ||
| "jobs": [ | ||
| { | ||
| "type": "async-index-build", | ||
| "content": { | ||
| "source": { | ||
| "index-source": "Build", | ||
| "data_type": "float32", | ||
| "data": "disk_index_siftsmall_learn_256pts_data.fbin", | ||
| "distance": "squared_l2", | ||
| "max_degree": 32, | ||
| "l_build": 50, | ||
| "alpha": 1.2, | ||
| "backedge_ratio": 1.0, | ||
| "num_threads": 1, | ||
| "num_start_points": 1, | ||
| "num_insert_attempts": 1, | ||
| "saturate_inserts": false, | ||
| "start_point_strategy": "medoid" | ||
| }, | ||
| "search_phase": { | ||
| "search-type": "topk-two-queue-filter", | ||
| "queries": "disk_index_sample_query_10pts.fbin", | ||
| "groundtruth": "gt_small_filter.bin", | ||
| "query_predicates": "query.10.label.jsonl", | ||
| "data_labels": "data.256.label.jsonl", | ||
| "max_candidates": [500, 1000, 2000], | ||
| "result_size_factor": 10, | ||
| "reps": 5, | ||
| "num_threads": [ | ||
| 1 | ||
| ], | ||
| "runs": [ | ||
| { | ||
| "search_n": 20, | ||
| "search_l": [ | ||
| 100, | ||
| 200 | ||
| ], | ||
| "recall_k": 10 | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } |
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
Oops, something went wrong.
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.
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.
I'm a little worried about what adding this universally will do for compile times. Ideally, we'd have a more focused way to add extensions like this that don't encroach on our hard-won compile-time reduction efforts. It would require some backend shuffling, but I think there is a world where search phases behave more like plugins rather than enums, so we can target specific monomorphizations instead of forcing this on all instances.
What've you observed in terms of compile time differences here?