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

Filter HNSW during BFS in a single pass #1940

Merged
merged 14 commits into from
Mar 14, 2024
Merged

Conversation

javitonino
Copy link
Contributor

Description

Describe the proposed changes made in this PR.

How was this PR tested?

Describe how you tested this PR.

Copy link

codecov bot commented Mar 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.93%. Comparing base (e7b2485) to head (961eb34).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1940      +/-   ##
==========================================
- Coverage   83.97%   83.93%   -0.04%     
==========================================
  Files         329      329              
  Lines       18708    18708              
==========================================
- Hits        15710    15703       -7     
- Misses       2998     3005       +7     
Flag Coverage Δ
ingest 68.72% <ø> (ø)
node-sidecar 94.15% <ø> (-1.64%) ⬇️
sdk 87.85% <ø> (ø)
utils 82.61% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

// We just need to perform BFS, the replacement is the closest node to the actual
// best solution. This algorithm takes a lazy approach to computing the similarity of
// candidates.
let mut visited_nodes = HashSet::new();
let mut candidates = VecDeque::from([x]);
let mut visited = HashSet::new();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can go ~30% faster by replacing this with a bitfield or similar. A HashSet is too slow in the case where we need to scan many nodes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just did it for funsies 😝

Copy link
Contributor

Choose a reason for hiding this comment

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

you can also use FxHashSet which is not cryptographically secure, so its way faster.

Copy link
Contributor

@hermeGarcia hermeGarcia left a comment

Choose a reason for hiding this comment

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

Just one thing to discuss!

nucliadb_vectors/src/data_point/ops_hnsw.rs Outdated Show resolved Hide resolved
let mut neighbours = vec![(entry_point.node, 0.)];
while crnt_layer != 0 {
for crnt_layer in (0..=entry_point.layer).rev() {
Copy link
Contributor

Choose a reason for hiding this comment

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

we were skipping layer 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hah, I thought it was on purpose. Should have asked!

@hermeGarcia hermeGarcia merged commit b55c6fd into main Mar 14, 2024
105 checks passed
@hermeGarcia hermeGarcia deleted the single_vectors_bfs_search branch March 14, 2024 15:16
vangheem added a commit that referenced this pull request Mar 14, 2024
vangheem added a commit that referenced this pull request Mar 14, 2024
@hermeGarcia hermeGarcia mentioned this pull request Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants