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

support safe update #308

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

support safe update #308

wants to merge 1 commit into from

Conversation

ShawnShawnYou
Copy link
Collaborator

@ShawnShawnYou ShawnShawnYou commented Jan 9, 2025

  • add vector check for update
  • if new vector is far from original vector, the update operation is failed

closes: #225

LOG_ERROR_AND_RETURNS(ErrorType::INVALID_ARGUMENT,
fmt::format("failed to pretrain(invalid argument): base tag id "
"({}) doesn't belong to index",
base_tag_id));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

a minor fix: error message "bas tag id" to "base tag id"

* @return result indicates whether the update operation is successful.
*/
virtual tl::expected<bool, Error>
UpdateVector(int64_t id, const DatasetPtr& new_base, bool need_fine_tune = false) {
UpdateVector(int64_t id, const DatasetPtr& new_base, bool force_update = false) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

p.s. We are not responsible for the consequences of this interface if the user specifies force_update = true

Copy link

codecov bot commented Jan 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

see 19 files with indirect coverage changes

Copy link
Collaborator

@wxyucs wxyucs left a comment

Choose a reason for hiding this comment

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

lgtm

"ef_search": {}
}}
}})",
vsag::UPDATE_CHECK_SEARCH_L),
Copy link
Collaborator

Choose a reason for hiding this comment

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

indent

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

float neighbor_dist =
std::reinterpret_pointer_cast<hnswlib::HierarchicalNSW>(alg_hnsw_)
->getDistanceByLabel(result.value()->GetIds()[i], new_base_vec);
if (neighbor_dist < self_dist) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here need set a range limit ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can implicitly check the range by checking the neighborhood relationship, since it's hard to directly give a range that is general for every dataset. Besides, if the nearest neighbor of the updated vector is still the old vector, it remains our assumption of this interface (the updated vector stays in a nearby area around the original vector).

for (int i = 0; i < result.value()->GetDim(); i++) {
float neighbor_dist =
std::reinterpret_pointer_cast<hnswlib::HierarchicalNSW>(alg_hnsw_)
->getDistanceByLabel(result.value()->GetIds()[i], new_base_vec);
Copy link
Collaborator

Choose a reason for hiding this comment

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

#309 provides a batch interface, which can be considered for use later on

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fix this in other pr?

Signed-off-by: zhongxiaoyao.zxy <[email protected]>
@ShawnShawnYou ShawnShawnYou self-assigned this Jan 10, 2025
@ShawnShawnYou ShawnShawnYou added the kind/improvement Code improvements (variable/function renaming, refactoring, etc. ) label Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/improvement Code improvements (variable/function renaming, refactoring, etc. ) size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support in-place update
4 participants