Skip to content

Commit d3edd09

Browse files
[8.2] [MOD-10185] add SVS fp16 tests (#802)
* [MOD-10185] add SVS fp16 tests (#740) * add fp16 tests * more tests * add printing utility to VecSimQueryReply and VecSimQueryResult more tests * more tests add validateSVSIndexAttributesInfo to compare info to params add populate_float16_vec * more tests * imp getStoredVectorDataByLabel for multi and no-compressed more tests * fix quant_modes * multi index tests * tiered tests * fix test to fail * temproraly push test_override_all to float32 tests * update to crash * revert svs tests chnages fix cosine batch iterators tests and all fp16 tests * test * add range test * skip test_get_distance for scalaar quant * align svs_get_distance name test with test_svs.cpp * clean ups * add coverage to print VecSimQueryResult and VecSimQueryReply * guard validateSVSIndexAttributesInfo with #if HAVE_SVS for the include * fix * align names with main branhc (cherry picked from commit 00bf35d) * remove multi block * fix * remove multi tiered tests * revert to align with master --------- Co-authored-by: meiravgri <[email protected]> Co-authored-by: meiravgri <[email protected]>
1 parent ee075bc commit d3edd09

File tree

8 files changed

+2935
-7
lines changed

8 files changed

+2935
-7
lines changed

src/VecSim/algorithms/svs/svs.h

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,44 @@ class SVSIndex : public VecSimIndexAbstract<svs_details::vecsim_dt<DataType>, fl
692692
public:
693693
void fitMemory() override {}
694694
std::vector<std::vector<char>> getStoredVectorDataByLabel(labelType label) const override {
695-
assert(false && "Not implemented");
696-
return {};
695+
696+
// For compressed/quantized indices, this function is not meaningful
697+
// since the stored data is in compressed format and not directly accessible
698+
if constexpr (QuantBits > 0 || ResidualBits > 0) {
699+
throw std::runtime_error(
700+
"getStoredVectorDataByLabel is not supported for compressed/quantized indices");
701+
} else {
702+
703+
std::vector<std::vector<char>> vectors_output;
704+
705+
if constexpr (isMulti) {
706+
// Multi-index case: get all vectors for this label
707+
auto it = impl_->get_label_to_external_lookup().find(label);
708+
if (it != impl_->get_label_to_external_lookup().end()) {
709+
const auto &external_ids = it->second;
710+
for (auto external_id : external_ids) {
711+
auto indexed_span = impl_->get_parent_index().get_datum(external_id);
712+
713+
// For uncompressed data, indexed_span should be a simple span
714+
const char *data_ptr = reinterpret_cast<const char *>(indexed_span.data());
715+
std::vector<char> vec_data(this->getStoredDataSize());
716+
std::memcpy(vec_data.data(), data_ptr, this->getStoredDataSize());
717+
vectors_output.push_back(std::move(vec_data));
718+
}
719+
}
720+
} else {
721+
// Single-index case
722+
auto indexed_span = impl_->get_datum(label);
723+
724+
// For uncompressed data, indexed_span should be a simple span
725+
const char *data_ptr = reinterpret_cast<const char *>(indexed_span.data());
726+
std::vector<char> vec_data(this->getStoredDataSize());
727+
std::memcpy(vec_data.data(), data_ptr, this->getStoredDataSize());
728+
vectors_output.push_back(std::move(vec_data));
729+
}
730+
731+
return vectors_output;
732+
}
697733
}
698734
void getDataByLabel(
699735
labelType label,

src/VecSim/query_result_definitions.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,20 @@ struct VecSimQueryReply {
3737
VecSimQueryReply_Code code = VecSim_QueryReply_OK)
3838
: results(allocator), code(code) {}
3939
};
40+
41+
#ifdef BUILD_TESTS
42+
#include <iostream>
43+
44+
// Print operators
45+
inline std::ostream &operator<<(std::ostream &os, const VecSimQueryResult &result) {
46+
os << "id: " << result.id << ", score: " << result.score;
47+
return os;
48+
}
49+
50+
inline std::ostream &operator<<(std::ostream &os, const VecSimQueryReply &reply) {
51+
for (const auto &result : reply.results) {
52+
os << result << std::endl;
53+
}
54+
return os;
55+
}
56+
#endif

tests/unit/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ add_executable(test_fp16 ../utils/mock_thread_pool.cpp test_fp16.cpp unit_test_u
4747
add_executable(test_int8 ../utils/mock_thread_pool.cpp test_int8.cpp unit_test_utils.cpp)
4848
add_executable(test_uint8 ../utils/mock_thread_pool.cpp test_uint8.cpp unit_test_utils.cpp)
4949
add_executable(test_index_test_utils ../utils/mock_thread_pool.cpp test_index_test_utils.cpp unit_test_utils.cpp)
50-
add_executable(test_svs ../utils/mock_thread_pool.cpp test_svs.cpp test_svs_tiered.cpp test_svs_multi.cpp unit_test_utils.cpp)
50+
add_executable(test_svs ../utils/mock_thread_pool.cpp test_svs.cpp test_svs_tiered.cpp test_svs_multi.cpp test_svs_fp16.cpp unit_test_utils.cpp)
5151

5252
target_link_libraries(test_hnsw PUBLIC gtest_main VectorSimilarity)
5353
target_link_libraries(test_hnsw_parallel PUBLIC gtest_main VectorSimilarity)

tests/unit/test_index_test_utils.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,20 @@ void IndexTestUtilsTest::get_stored_vector_data_single_test() {
245245
EXPECT_NO_FATAL_FAILURE(this->ValidateVectors(stored_data, i));
246246
}
247247
}
248+
249+
TEST(QueryResultPrintTest, PrintOperators) {
250+
// Test VecSimQueryResult print operator
251+
VecSimQueryResult result = {.id = 42, .score = 3.14};
252+
std::ostringstream oss1;
253+
oss1 << result;
254+
EXPECT_EQ(oss1.str(), "id: 42, score: 3.14");
255+
256+
// Test VecSimQueryReply print operator
257+
VecSimQueryReply reply(VecSimAllocator::newVecsimAllocator());
258+
reply.results.push_back({.id = 1, .score = 1.5});
259+
reply.results.push_back({.id = 2, .score = 2.5});
260+
261+
std::ostringstream oss2;
262+
oss2 << reply;
263+
EXPECT_EQ(oss2.str(), "id: 1, score: 1.5\nid: 2, score: 2.5\n");
264+
}

0 commit comments

Comments
 (0)