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

Is the comment of HNSW::shrink_neighbor_list wrong? #2978

Closed
yockie opened this issue Jul 30, 2023 · 2 comments
Closed

Is the comment of HNSW::shrink_neighbor_list wrong? #2978

yockie opened this issue Jul 30, 2023 · 2 comments

Comments

@yockie
Copy link
Contributor

yockie commented Jul 30, 2023

https://github.com/facebookresearch/faiss/blob/821a401ae9ecee7f6b18c5dea70021a88acbc88b/faiss/impl/HNSW.cpp#L225C42-L225C42

I read HNSW::shrink_neighbor_list source very carefully, I'm sure that this comment is wrong. It enumerates vertices from nearest to farthest, not from farthest to nearest.

Here's my analysis:
(1)notice the definition of NodeDistFarther

struct NodeDistFarther {
    float d;
    int id;
    NodeDistFarther(float d, int id) : d(d), id(id) {}
    bool operator<(const NodeDistFarther& obj1) const {
        return d > obj1.d;
    }
};

std::priority_queue<NodeDistFarther> input

(2)
It means that the top of input is the node that d is the minimum,and d means the distance。
The smaller the d, the closer the distance(It is also true for inner product metric because d is the opposite of the inner product value)。
(3)Here is a simple test of "std::priority_queue<NodeDistFarther>"
image

@mdouze
Copy link
Contributor

mdouze commented Jul 31, 2023

Hmmm it looks like you're right.
Would you mind submitting a PR with the corrected comment?

@yockie
Copy link
Contributor Author

yockie commented Jul 31, 2023

Hmmm it looks like you're right. Would you mind submitting a PR with the corrected comment?

OK,here is the PR: #2980

facebook-github-bot pushed a commit that referenced this issue Aug 1, 2023
Summary:
This pr is to fix the issue #2978 .

Pull Request resolved: #2980

Reviewed By: mdouze

Differential Revision: D47950592

Pulled By: mlomeli1

fbshipit-source-id: 32ef06c3775f7234a5a4bb4dab36c176edea2d1f
@mlomeli1 mlomeli1 closed this as completed Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants