Skip to content

Commit a3ee719

Browse files
committed
basic integrity check
1 parent fb9eb00 commit a3ee719

File tree

2 files changed

+6
-20
lines changed

2 files changed

+6
-20
lines changed

src/VecSim/algorithms/svs/svs.h

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
#ifdef BUILD_TESTS
3030
#include "VecSim/utils/serializer.h"
31-
#endif
3231

3332
#define SVS_INVALID_META_DATA SIZE_MAX
3433

@@ -40,10 +39,10 @@ typedef struct {
4039
size_t label_count;
4140
size_t capacity;
4241
size_t changes_count;
43-
size_t graph_entry_point;
4442
bool is_compressed;
4543
bool is_multi;
4644
} SVSIndexMetaData;
45+
#endif
4746

4847
struct SVSIndexBase
4948
#ifdef BUILD_TESTS
@@ -59,6 +58,7 @@ struct SVSIndexBase
5958
virtual size_t getThreadPoolCapacity() const = 0;
6059
virtual bool isCompressed() const = 0;
6160
#ifdef BUILD_TESTS
61+
virtual SVSIndexMetaData checkIntegrity() const = 0;
6262
virtual void loadIndex(const std::string &folder_path) = 0;
6363
virtual svs::logging::logger_ptr getLogger() const = 0;
6464
#endif
@@ -619,15 +619,14 @@ class SVSIndex : public VecSimIndexAbstract<svs_details::vecsim_dt<DataType>, fl
619619
}
620620
}
621621

622-
SVSIndexMetaData checkIntegrity() const {
622+
SVSIndexMetaData checkIntegrity() const override {
623623
SVSIndexMetaData res = {.valid_state = false,
624624
.memory_usage = -1,
625625
.index_size = SVS_INVALID_META_DATA,
626626
.storage_size = SVS_INVALID_META_DATA,
627627
.label_count = SVS_INVALID_META_DATA,
628628
.capacity = SVS_INVALID_META_DATA,
629629
.changes_count = SVS_INVALID_META_DATA,
630-
.graph_entry_point = SVS_INVALID_META_DATA,
631630
.is_compressed = false,
632631
.is_multi = isMulti};
633632

@@ -668,25 +667,15 @@ class SVSIndex : public VecSimIndexAbstract<svs_details::vecsim_dt<DataType>, fl
668667
return res;
669668
}
670669

671-
// Check graph entry point validity
672-
try {
673-
auto entry_point = impl_->get_entry_point();
674-
res.graph_entry_point = entry_point;
675-
676-
// Entry point should be valid (less than index size) if index is not empty
677-
if (res.index_size > 0 && entry_point >= res.index_size) {
678-
return res;
679-
}
680-
} catch (...) {
681-
// If we can't get entry point, that's a problem
682-
return res;
683-
}
684670

685671
// Validate label consistency by checking a sample of labels
686672
size_t label_validation_errors = 0;
687673
size_t labels_checked = 0;
688674
const size_t max_labels_to_check = std::min(res.index_size, size_t{1000});
689675

676+
// Iterate over a sample of labels using a lambda that captures validation counters by reference.
677+
// The lambda checks for invalid labels (e.g., SIZE_MAX) and increments the error counter directly.
678+
690679
impl_->on_ids([&](size_t label) {
691680
if (labels_checked >= max_labels_to_check) {
692681
return;
@@ -731,8 +720,6 @@ class SVSIndex : public VecSimIndexAbstract<svs_details::vecsim_dt<DataType>, fl
731720

732721
svs::logging::logger_ptr getLogger() const override { return logger_; }
733722

734-
// Validates the integrity of a loaded SVS index
735-
SVSIndexMetaData checkIntegrity() const;
736723
#endif
737724
};
738725

tests/unit/test_svs.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2641,7 +2641,6 @@ TEST(SVSTest, save_load) {
26412641
EXPECT_EQ(integrity_result.storage_size, n) << "Storage size should match index size";
26422642
EXPECT_EQ(integrity_result.label_count, n) << "Label count should match expected";
26432643
EXPECT_GE(integrity_result.capacity, n) << "Capacity should be at least index size";
2644-
EXPECT_LT(integrity_result.graph_entry_point, n) << "Entry point should be valid";
26452644
EXPECT_FALSE(integrity_result.is_multi) << "This should be a single index";
26462645

26472646
VecSimIndex_Free(index);

0 commit comments

Comments
 (0)