Skip to content

Commit e89eaa8

Browse files
authored
Merge pull request #27 from chroma-core/revert-26-revert-24-12-30-_enh_change_assertions_in_integrity_validation_to_exceptions
Revert "Revert "[ENH] Change assertions in integrity validation to exceptions""
2 parents c299833 + 41b1501 commit e89eaa8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

hnswlib/hnswalg.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -1835,21 +1835,22 @@ namespace hnswlib
18351835
std::unordered_set<tableint> s;
18361836
for (int j = 0; j < size; j++)
18371837
{
1838-
assert(data[j] > 0);
1839-
assert(data[j] < cur_element_count);
1840-
assert(data[j] != i);
1838+
if (data[j] < 0 || data[j] >= cur_element_count || data[j] == i)
1839+
throw std::runtime_error("HNSW Integrity failure: invalid neighbor index");
18411840
inbound_connections_num[data[j]]++;
18421841
s.insert(data[j]);
18431842
connections_checked++;
18441843
}
1845-
assert(s.size() == size);
1844+
if (s.size() != size)
1845+
throw std::runtime_error("HNSW Integrity failure: duplicate neighbor index");
18461846
}
18471847
}
18481848
if (cur_element_count > 1)
18491849
{
18501850
int min1 = inbound_connections_num[0], max1 = inbound_connections_num[0];
18511851
for (int i = 0; i < cur_element_count; i++)
18521852
{
1853+
// This should always be true regardless the data is corrupted or not
18531854
assert(inbound_connections_num[i] > 0);
18541855
min1 = std::min(inbound_connections_num[i], min1);
18551856
max1 = std::max(inbound_connections_num[i], max1);

0 commit comments

Comments
 (0)