Skip to content

Commit

Permalink
Merge pull request #26 from chroma-core/revert-24-12-30-_enh_change_a…
Browse files Browse the repository at this point in the history
…ssertions_in_integrity_validation_to_exceptions

Revert "[ENH] Change assertions in integrity validation to exceptions"
rescrv authored Jan 2, 2025
2 parents e434afb + 0198aff commit c299833
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions hnswlib/hnswalg.h
Original file line number Diff line number Diff line change
@@ -1835,22 +1835,21 @@ namespace hnswlib
std::unordered_set<tableint> s;
for (int j = 0; j < size; j++)
{
if (data[j] < 0 || data[j] >= cur_element_count || data[j] == i)
throw std::runtime_error("HNSW Integrity failure: invalid neighbor index");
assert(data[j] > 0);
assert(data[j] < cur_element_count);
assert(data[j] != i);
inbound_connections_num[data[j]]++;
s.insert(data[j]);
connections_checked++;
}
if (s.size() != size)
throw std::runtime_error("HNSW Integrity failure: duplicate neighbor index");
assert(s.size() == size);
}
}
if (cur_element_count > 1)
{
int min1 = inbound_connections_num[0], max1 = inbound_connections_num[0];
for (int i = 0; i < cur_element_count; i++)
{
// This should always be true regardless the data is corrupted or not
assert(inbound_connections_num[i] > 0);
min1 = std::min(inbound_connections_num[i], min1);
max1 = std::max(inbound_connections_num[i], max1);

0 comments on commit c299833

Please sign in to comment.