-
Notifications
You must be signed in to change notification settings - Fork 35
Make index blocksize flexible #248
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
razdoburdin
wants to merge
3
commits into
intel:main
Choose a base branch
from
razdoburdin:flex_blocksize
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 all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -63,6 +63,8 @@ struct DynamicVamanaIndexManagerBase : public DynamicVamanaIndex { | |
| }); | ||
| } | ||
|
|
||
| size_t blocksize_bytes() const noexcept { return impl_->blocksize_bytes(); } | ||
|
|
||
| Status | ||
| remove_selected(size_t* num_removed, const IDFilter& selector) noexcept override { | ||
| return runtime_error_wrapper([&] { | ||
|
|
@@ -136,19 +138,40 @@ Status DynamicVamanaIndex::check_storage_kind(StorageKind storage_kind) noexcept | |
| ); | ||
| } | ||
|
|
||
| Status DynamicVamanaIndex::check_params( | ||
| const DynamicVamanaIndex::DynamicIndexParams& dynamic_index_params | ||
| ) noexcept { | ||
| constexpr static size_t kMaxBlockSizeExp = 30; // 1GB | ||
| constexpr static size_t kMinBlockSizeExp = 12; // 4KB | ||
|
|
||
| if (dynamic_index_params.blocksize_exp > kMaxBlockSizeExp) | ||
| return Status(ErrorCode::INVALID_ARGUMENT, "Blocksize is too large"); | ||
|
|
||
| if (dynamic_index_params.blocksize_exp < kMinBlockSizeExp) | ||
| return Status(ErrorCode::INVALID_ARGUMENT, "Blocksize is too small"); | ||
|
|
||
| return Status_Ok; | ||
| } | ||
|
|
||
| Status DynamicVamanaIndex::build( | ||
| DynamicVamanaIndex** index, | ||
| size_t dim, | ||
| MetricType metric, | ||
| StorageKind storage_kind, | ||
| const DynamicVamanaIndex::BuildParams& params, | ||
| const DynamicVamanaIndex::SearchParams& default_search_params | ||
| const DynamicVamanaIndex::SearchParams& default_search_params, | ||
| const DynamicVamanaIndex::DynamicIndexParams& dynamic_index_params | ||
| ) noexcept { | ||
| using Impl = DynamicVamanaIndexImpl; | ||
| *index = nullptr; | ||
|
|
||
| auto status = DynamicVamanaIndex::check_params(dynamic_index_params); | ||
| if (!status.ok()) | ||
| return status; | ||
|
|
||
| return runtime_error_wrapper([&] { | ||
| auto impl = std::make_unique<Impl>( | ||
| dim, metric, storage_kind, params, default_search_params | ||
| dim, metric, storage_kind, params, default_search_params, dynamic_index_params | ||
| ); | ||
| *index = new DynamicVamanaIndexManagerBase<Impl>{std::move(impl)}; | ||
| }); | ||
|
|
@@ -181,13 +204,20 @@ Status DynamicVamanaIndexLeanVec::build( | |
| StorageKind storage_kind, | ||
| size_t leanvec_dims, | ||
| const DynamicVamanaIndex::BuildParams& params, | ||
| const DynamicVamanaIndex::SearchParams& default_search_params | ||
| const DynamicVamanaIndex::SearchParams& default_search_params, | ||
| const DynamicVamanaIndex::DynamicIndexParams& dynamic_index_params | ||
| ) noexcept { | ||
| using Impl = DynamicVamanaIndexLeanVecImpl; | ||
| *index = nullptr; | ||
| return runtime_error_wrapper([&] { | ||
| auto impl = std::make_unique<Impl>( | ||
| dim, metric, storage_kind, leanvec_dims, params, default_search_params | ||
| dim, | ||
| metric, | ||
| storage_kind, | ||
| leanvec_dims, | ||
| params, | ||
| default_search_params, | ||
| dynamic_index_params | ||
| ); | ||
| *index = new DynamicVamanaIndexManagerBase<Impl>{std::move(impl)}; | ||
| }); | ||
|
|
@@ -201,15 +231,22 @@ Status DynamicVamanaIndexLeanVec::build( | |
| StorageKind storage_kind, | ||
| const LeanVecTrainingData* training_data, | ||
| const DynamicVamanaIndex::BuildParams& params, | ||
| const DynamicVamanaIndex::SearchParams& default_search_params | ||
| const DynamicVamanaIndex::SearchParams& default_search_params, | ||
| const DynamicVamanaIndex::DynamicIndexParams& dynamic_index_params | ||
| ) noexcept { | ||
| using Impl = DynamicVamanaIndexLeanVecImpl; | ||
| *index = nullptr; | ||
| return runtime_error_wrapper([&] { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
| auto training_data_impl = | ||
| static_cast<const LeanVecTrainingDataManager*>(training_data)->impl_; | ||
| auto impl = std::make_unique<Impl>( | ||
| dim, metric, storage_kind, training_data_impl, params, default_search_params | ||
| dim, | ||
| metric, | ||
| storage_kind, | ||
| training_data_impl, | ||
| params, | ||
| default_search_params, | ||
| dynamic_index_params | ||
| ); | ||
| *index = new DynamicVamanaIndexManagerBase<Impl>{std::move(impl)}; | ||
| }); | ||
|
|
@@ -218,15 +255,15 @@ Status DynamicVamanaIndexLeanVec::build( | |
| #else // SVS_LEANVEC_HEADER | ||
| // LeanVec storage kind is not supported in this build configuration | ||
| Status DynamicVamanaIndexLeanVec:: | ||
| build(DynamicVamanaIndex**, size_t, MetricType, StorageKind, size_t, const DynamicVamanaIndex::BuildParams&, const DynamicVamanaIndex::SearchParams&) noexcept { | ||
| build(DynamicVamanaIndex**, size_t, MetricType, StorageKind, size_t, const DynamicVamanaIndex::BuildParams&, const DynamicVamanaIndex::SearchParams&, const DynamicVamanaIndex::DynamicIndexParams&) noexcept { | ||
| return Status( | ||
| ErrorCode::NOT_IMPLEMENTED, | ||
| "DynamicVamanaIndexLeanVec is not supported in this build configuration." | ||
| ); | ||
| } | ||
|
|
||
| Status DynamicVamanaIndexLeanVec:: | ||
| build(DynamicVamanaIndex**, size_t, MetricType, StorageKind, const LeanVecTrainingData*, const DynamicVamanaIndex::BuildParams&, const DynamicVamanaIndex::SearchParams&) noexcept { | ||
| build(DynamicVamanaIndex**, size_t, MetricType, StorageKind, const LeanVecTrainingData*, const DynamicVamanaIndex::BuildParams&, const DynamicVamanaIndex::SearchParams&, const DynamicVamanaIndex::DynamicIndexParams&) noexcept { | ||
| return Status( | ||
| ErrorCode::NOT_IMPLEMENTED, | ||
| "DynamicVamanaIndexLeanVec is not supported in this build configuration." | ||
|
|
||
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.
Does it make sense to call
DynamicVamanaIndex::check_params()here as it is done inDynamicVamanaIndex::build()?