-
Notifications
You must be signed in to change notification settings - Fork 179
Bug: Wrong memory override lead to a violation of HNSW algorithm which will lead to a decrease of recall rate. #576
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
Comments
Hi @ycw66! When I've shared the code for USearch, I didn't expect people to go that deep into it's logic, so I'm very excited to see this issue the proposed #575 patch. I hope this waits a few days until the next week, was planning to refactor a few bits and pieces in the USearch and your suggestions would fit right in 😉 |
Thank you Ash! USearch is a popular high-performance library for vector search. I am trying to adapt USearch to our project, a universal data layer, to build the distributed vector database. Our system have a universal data layer can provide the ability of auto-scale, cache, ACID transaction and fault-tolerance. I just want to adapt the USearch to our universal data layer. When I do this, I need slightly modify the original code of USearch and find this bug. |
Hi ash, I wanna know if this bug is verified and fixed? |
Hi @ashvardanian ! I conduct a recall test and find when fix this bug with this PR#575, recall can improve more than 10%. My test config is as follows:
|
Nice! Any chance you have any larger-scale results? Maybe at least 10M vectors? |
I will test this and then show the result |
@ashvardanian I increase the numbers of vector to 1M. When bug not fixed, the average recall is 8.82%. When this bug fixed, the average recall is 17.27%. I think because the dataset is randomly generated so the recall rate is very low compared with these general dataset in the ANN Index Benchmark. Anyway, I think this bug can lead to a decrease of recall rate and can be fixed with minimal change. I kindly ask whether the PR#575 can be merged or any other code should change? |
Hi @ashvardanian , I further conduct tests on another two datasets from ANN Benchmark, SIFT and DEEP1B. Test results are as follows:
Results show this bug will decrease recall rate a lot! |
Looks very promising! Thank you @ycw66! |
Describe the bug
Problem statement
A critical memory corruption occurs in form_reverse_links_ when
new_neighbors
(a view of context.top) becomes invalidated during iteration.new_neighbors
is a view ofcontext.top
, during traversal ofnew_neighbors
,context.top
may be modified to complete the functionrefine_
, therefore corrupt the 'new_neighbors' as it is just a view.Subsequent accesses to
new_neighbors
afterrefine_
function on a corrupted/stale memory range, leading to a violation of HNSW algorithmIn a word, the following code will cause some correctness problem, it will lead to some wrong links among nodes that will never appear in original HNSW algorithm.
form_reverse_links_
function is as follows:Steps to reproduce
form_reverse_link_
, here is accurate code postion: linknew_neighbors
when you reach the breakpoint.new_neighbours
, which should not be changed.Expected behavior
During the execution of the function
form_reverse_link_
, thenew_neighbors
should never be changed.USearch version
latest
Operating System
Ubuntu 24.04
Hardware architecture
x86
Which interface are you using?
C++ implementation
Contact Details
No response
Are you open to being tagged as a contributor?
.git
history as a contributorIs there an existing issue for this?
Code of Conduct
The text was updated successfully, but these errors were encountered: