-
Notifications
You must be signed in to change notification settings - Fork 417
bf_tree migration away from diskann-providers #1020
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a4c41f3
Migrate bf_tree provider from PQ to spherical quantization
JordanMaples 21e81a7
new_empty and cargo remove publish step
JordanMaples eb2098e
fix publish workspace in cargo
JordanMaples da86885
remove the workspace specification from the cargo
JordanMaples 6a51d78
comments from pr
JordanMaples 1bd362b
change test to uniform initialization of the vectors in the matrix an…
JordanMaples 70da9e8
making start points distinct
JordanMaples 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,43 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT license. | ||
| [package] | ||
| name = "diskann-bftree" | ||
| version.workspace = true | ||
| description.workspace = true | ||
| authors.workspace = true | ||
| documentation.workspace = true | ||
| license.workspace = true | ||
| edition.workspace = true | ||
| publish = false | ||
|
|
||
| [dependencies] | ||
| bf-tree.workspace = true | ||
| bytemuck = { workspace = true, features = ["must_cast"] } | ||
| diskann.workspace = true | ||
| diskann-providers.workspace = true | ||
| diskann-quantization = { workspace = true, features = ["flatbuffers"] } | ||
| diskann-utils.workspace = true | ||
| diskann-vector.workspace = true | ||
| half = { workspace = true, features = ["bytemuck", "num-traits"] } | ||
| futures-util.workspace = true | ||
| rand.workspace = true | ||
| serde = { workspace = true, features = ["derive"] } | ||
| serde_json.workspace = true | ||
| thiserror.workspace = true | ||
| tokio = { workspace = true, features = ["rt", "rt-multi-thread"] } | ||
|
|
||
| [dev-dependencies] | ||
| diskann = { workspace = true, features = ["testing"] } | ||
| diskann-providers = { workspace = true, features = ["testing"] } | ||
| diskann-utils = { workspace = true, features = ["testing"] } | ||
| rstest.workspace = true | ||
| tempfile.workspace = true | ||
| tokio = { workspace = true, features = ["full"] } | ||
|
|
||
| [features] | ||
| default = [] | ||
| experimental_diversity_search = ["diskann/experimental_diversity_search"] | ||
|
|
||
| [lints] | ||
| workspace = true | ||
|
|
||
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,172 @@ | ||
| /* | ||
| * Copyright (c) Microsoft Corporation. | ||
| * Licensed under the MIT license. | ||
| */ | ||
|
|
||
| //! BfTree-based data provider for DiskANN async indexes. | ||
| //! | ||
| //! This crate provides a [`BfTree`](bf_tree::BfTree)-backed implementation of the DiskANN | ||
| //! [`DataProvider`](diskann::provider::DataProvider) trait, enabling indexes that can | ||
| //! transparently spill to disk for datasets larger than available memory. | ||
|
|
||
| pub mod neighbors; | ||
| pub mod provider; | ||
| pub mod quant; | ||
| pub mod vectors; | ||
|
|
||
| // Accessors | ||
| pub use provider::{ | ||
| AsVectorDtype, BfTreePaths, BfTreeProvider, BfTreeProviderParameters, CreateQuantProvider, | ||
| FullAccessor, GraphParams, Hidden, QuantAccessor, StartPoint, VectorDtype, | ||
| }; | ||
|
|
||
| pub use bf_tree::Config; | ||
|
|
||
| use diskann::{ | ||
| error::{RankedError, TransientError}, | ||
| ANNError, | ||
| }; | ||
|
|
||
| #[derive(Debug, Clone, Copy)] | ||
| pub struct NoStore; | ||
|
|
||
| /// Wrapper around [`bf_tree::ConfigError`] that implements [`std::error::Error`]. | ||
| #[derive(Debug, Clone)] | ||
| pub struct ConfigError(pub bf_tree::ConfigError); | ||
|
|
||
| impl std::fmt::Display for ConfigError { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| write!(f, "BfTree configuration error: {:?}", self.0) | ||
| } | ||
| } | ||
|
|
||
| impl std::error::Error for ConfigError {} | ||
|
|
||
| impl From<ConfigError> for ANNError { | ||
| #[track_caller] | ||
| #[inline(never)] | ||
| fn from(error: ConfigError) -> ANNError { | ||
| ANNError::new(diskann::ANNErrorKind::IndexError, error) | ||
| } | ||
| } | ||
|
|
||
| trait AsKey { | ||
| fn as_key(&self) -> &[u8]; | ||
| } | ||
|
|
||
| impl AsKey for usize { | ||
| fn as_key(&self) -> &[u8] { | ||
| bytemuck::bytes_of(self) | ||
| } | ||
| } | ||
|
|
||
| //////////// | ||
| // Errors // | ||
| //////////// | ||
| #[derive(Debug)] | ||
| pub enum VectorError { | ||
| /// the vector has been explicitly deleted | ||
| Deleted, | ||
| /// the key was not found | ||
| NotFound, | ||
| } | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct VectorUnavailable { | ||
| pub id: usize, | ||
| pub err: VectorError, | ||
| } | ||
|
|
||
| impl std::fmt::Display for VectorUnavailable { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| match self.err { | ||
| VectorError::Deleted => write!(f, "vector {} was deleted", self.id), | ||
| VectorError::NotFound => write!(f, "vector {} not found", self.id), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl TransientError<ANNError> for VectorUnavailable { | ||
| fn acknowledge<D>(self, _why: D) | ||
| where | ||
| D: std::fmt::Display, | ||
| { | ||
| // no-op: we are expecting transient deletion errors during traversal | ||
| } | ||
|
|
||
| fn escalate<D>(self, why: D) -> ANNError | ||
| where | ||
| D: std::fmt::Display, | ||
| { | ||
| ANNError::log_index_error(format!("{self}, escalated: {why}")) | ||
| } | ||
| } | ||
|
|
||
| pub type AccessError = RankedError<VectorUnavailable, ANNError>; | ||
|
|
||
| /// Metrics recorded by [`DefaultContext`](diskann::provider::DefaultContext). | ||
| #[derive(Debug, Clone)] | ||
| #[cfg_attr(test, derive(serde::Serialize, serde::Deserialize))] | ||
| pub struct ContextMetrics { | ||
| pub spawns: usize, | ||
| pub clones: usize, | ||
| } | ||
|
|
||
| /// An atomic call counter used for test instrumentation. | ||
| /// | ||
| /// Under `#[cfg(test)]`, this is a real atomic counter. In production builds, | ||
| /// all methods are no-ops that the compiler can eliminate entirely. | ||
| #[cfg(test)] | ||
| pub(crate) struct TestCallCount { | ||
| count: std::sync::atomic::AtomicUsize, | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| impl TestCallCount { | ||
| pub fn new() -> Self { | ||
| Self { | ||
| count: std::sync::atomic::AtomicUsize::new(0), | ||
| } | ||
| } | ||
|
|
||
| pub fn enabled() -> bool { | ||
| true | ||
| } | ||
|
|
||
| pub fn increment(&self) { | ||
| self.count | ||
| .fetch_add(1, std::sync::atomic::Ordering::Relaxed); | ||
| } | ||
|
|
||
| pub fn get(&self) -> usize { | ||
| self.count.load(std::sync::atomic::Ordering::Relaxed) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(not(test))] | ||
| #[allow(dead_code)] | ||
| pub(crate) struct TestCallCount {} | ||
|
JordanMaples marked this conversation as resolved.
|
||
|
|
||
| #[cfg(not(test))] | ||
| #[allow(dead_code)] | ||
| impl TestCallCount { | ||
| pub fn new() -> Self { | ||
| Self {} | ||
| } | ||
|
|
||
| pub fn enabled() -> bool { | ||
| false | ||
| } | ||
|
|
||
| pub fn increment(&self) {} | ||
|
|
||
| pub fn get(&self) -> usize { | ||
| 0 | ||
| } | ||
| } | ||
|
|
||
| impl Default for TestCallCount { | ||
| fn default() -> Self { | ||
| Self::new() | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.