1 Commits
Author SHA1 Message Date
Justin Gibbs 66853ee41d Fix NSG off-by-one neighbor ID check (#4804)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/4804

Valid neighbor indexes are in the range of [0, ntotal). Fix range check in
NSG::search_on_graph() that accepted an index value of ntotal.

NOTE: This data structure uses -1 as a termninal sentinal. The call to
nsg::Graph::get_neighgbors() above the for loop that includes the upper bound
check stops when encountering a negative index. This means the check for
negative values has already occurred and does not need to be repeated inside
the loop.

Reviewed By: junjieqi, sh00s

Differential Revision: D93040548

fbshipit-source-id: e1bde990a459c86dfaebdd2f780375b7922fc5f5
2026-02-12 21:09:31 -08:00