Skip to content

Commit

Permalink
Fix an incorrectly counted the number of computed distances for HNSW (#…
Browse files Browse the repository at this point in the history
…3840)

Summary:
#3819

A definite bug in my code from the past.
The number of reported distances is higher that the number of distances actually computed.

Pull Request resolved: #3840

Reviewed By: junjieqi

Differential Revision: D62392577

Pulled By: mengdilin

fbshipit-source-id: c4d595849cc95e77eb6cd8d499b3128bbe9a6e13
  • Loading branch information
alexanderguzhva authored and facebook-github-bot committed Sep 9, 2024
1 parent 3f41161 commit 21dfdba
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions faiss/impl/HNSW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,6 @@ int search_from_candidates(
int counter = 0;
size_t saved_j[4];

ndis += jmax - begin;
threshold = res.threshold;

auto add_to_heap = [&](const size_t idx, const float dis) {
Expand Down Expand Up @@ -814,13 +813,17 @@ int search_from_candidates(
add_to_heap(saved_j[id4], dis[id4]);
}

ndis += 4;

counter = 0;
}
}

for (size_t icnt = 0; icnt < counter; icnt++) {
float dis = qdis(saved_j[icnt]);
add_to_heap(saved_j[icnt], dis);

ndis += 1;
}
}

Expand Down Expand Up @@ -919,8 +922,6 @@ std::priority_queue<HNSW::Node> search_from_candidate_unbounded(
int counter = 0;
size_t saved_j[4];

ndis += jmax - begin;

auto add_to_heap = [&](const size_t idx, const float dis) {
if (top_candidates.top().first > dis ||
top_candidates.size() < ef) {
Expand Down Expand Up @@ -957,13 +958,17 @@ std::priority_queue<HNSW::Node> search_from_candidate_unbounded(
add_to_heap(saved_j[id4], dis[id4]);
}

ndis += 4;

counter = 0;
}
}

for (size_t icnt = 0; icnt < counter; icnt++) {
float dis = qdis(saved_j[icnt]);
add_to_heap(saved_j[icnt], dis);

ndis += 1;
}
}

Expand Down

0 comments on commit 21dfdba

Please sign in to comment.