Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions src/VecSim/algorithms/svs/svs.h
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,44 @@ class SVSIndex : public VecSimIndexAbstract<svs_details::vecsim_dt<DataType>, fl
#ifdef BUILD_TESTS
void fitMemory() override {}
std::vector<std::vector<char>> getStoredVectorDataByLabel(labelType label) const override {
assert(false && "Not implemented");
return {};

// For compressed/quantized indices, this function is not meaningful
// since the stored data is in compressed format and not directly accessible
if constexpr (QuantBits > 0 || ResidualBits > 0) {
throw std::runtime_error(
"getStoredVectorDataByLabel is not supported for compressed/quantized indices");
} else {

std::vector<std::vector<char>> vectors_output;

if constexpr (isMulti) {
// Multi-index case: get all vectors for this label
auto it = impl_->get_label_to_external_lookup().find(label);
if (it != impl_->get_label_to_external_lookup().end()) {
const auto &external_ids = it->second;
for (auto external_id : external_ids) {
auto indexed_span = impl_->get_parent_index().get_datum(external_id);

// For uncompressed data, indexed_span should be a simple span
const char *data_ptr = reinterpret_cast<const char *>(indexed_span.data());
std::vector<char> vec_data(this->getDataSize());
std::memcpy(vec_data.data(), data_ptr, this->getDataSize());
vectors_output.push_back(std::move(vec_data));
}
}
} else {
// Single-index case
auto indexed_span = impl_->get_datum(label);

// For uncompressed data, indexed_span should be a simple span
const char *data_ptr = reinterpret_cast<const char *>(indexed_span.data());
std::vector<char> vec_data(this->getDataSize());
std::memcpy(vec_data.data(), data_ptr, this->getDataSize());
vectors_output.push_back(std::move(vec_data));
}

return vectors_output;
}
}
void getDataByLabel(
labelType label,
Expand Down
17 changes: 17 additions & 0 deletions src/VecSim/query_result_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,20 @@ struct VecSimQueryReply {
VecSimQueryReply_Code code = VecSim_QueryReply_OK)
: results(allocator), code(code) {}
};

#ifdef BUILD_TESTS
#include <iostream>

// Print operators
inline std::ostream &operator<<(std::ostream &os, const VecSimQueryResult &result) {
os << "id: " << result.id << ", score: " << result.score;
return os;
}

inline std::ostream &operator<<(std::ostream &os, const VecSimQueryReply &reply) {
for (const auto &result : reply.results) {
os << result << std::endl;
}
return os;
}
#endif
2 changes: 1 addition & 1 deletion tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ add_executable(test_fp16 ../utils/mock_thread_pool.cpp test_fp16.cpp unit_test_u
add_executable(test_int8 ../utils/mock_thread_pool.cpp test_int8.cpp unit_test_utils.cpp)
add_executable(test_uint8 ../utils/mock_thread_pool.cpp test_uint8.cpp unit_test_utils.cpp)
add_executable(test_index_test_utils ../utils/mock_thread_pool.cpp test_index_test_utils.cpp unit_test_utils.cpp)
add_executable(test_svs ../utils/mock_thread_pool.cpp test_svs.cpp test_svs_tiered.cpp test_svs_multi.cpp unit_test_utils.cpp)
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)

target_link_libraries(test_hnsw PUBLIC gtest_main VectorSimilarity)
target_link_libraries(test_hnsw_parallel PUBLIC gtest_main VectorSimilarity)
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_index_test_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,20 @@ void IndexTestUtilsTest::get_stored_vector_data_single_test() {
EXPECT_NO_FATAL_FAILURE(this->ValidateVectors(stored_data, i));
}
}

TEST(QueryResultPrintTest, PrintOperators) {
// Test VecSimQueryResult print operator
VecSimQueryResult result = {.id = 42, .score = 3.14};
std::ostringstream oss1;
oss1 << result;
EXPECT_EQ(oss1.str(), "id: 42, score: 3.14");

// Test VecSimQueryReply print operator
VecSimQueryReply reply(VecSimAllocator::newVecsimAllocator());
reply.results.push_back({.id = 1, .score = 1.5});
reply.results.push_back({.id = 2, .score = 2.5});

std::ostringstream oss2;
oss2 << reply;
EXPECT_EQ(oss2.str(), "id: 1, score: 1.5\nid: 2, score: 2.5\n");
}
Loading
Loading