|
18 | 18 | #include "VecSim/algorithms/hnsw/hnsw.h"
|
19 | 19 | #include "VecSim/algorithms/hnsw/hnsw_tiered.h"
|
20 | 20 | #include "VecSim/index_factories/hnsw_factory.h"
|
| 21 | +#include "VecSim/index_factories/svs_factory.h" |
| 22 | +#include "VecSim/algorithms/svs/svs.h" |
21 | 23 | #include "mock_thread_pool.h"
|
22 | 24 | #include "tests_utils.h"
|
23 | 25 | #include "VecSim/index_factories/tiered_factory.h"
|
|
28 | 30 | #include <cstdlib>
|
29 | 31 | #include <limits>
|
30 | 32 | #include <cmath>
|
| 33 | +#include <filesystem> |
31 | 34 | #include <random>
|
32 | 35 | #include <cstdarg>
|
33 | 36 | #include <filesystem>
|
@@ -512,6 +515,48 @@ TEST_F(SerializerTest, HNSWSerialzer) {
|
512 | 515 | output.close();
|
513 | 516 | }
|
514 | 517 |
|
| 518 | +#if HAVE_SVS |
| 519 | +TEST_F(SerializerTest, SVSSerializer) { |
| 520 | + |
| 521 | + this->file_name = std::string(getenv("ROOT")) + "/tests/unit/bad_index_svs"; |
| 522 | + auto metadata_path = std::filesystem::path(this->file_name) / "metadata"; |
| 523 | + |
| 524 | + // Try to load an index from a directory that doesn't exist. |
| 525 | + SVSParams params = { |
| 526 | + .type = VecSimType_FLOAT32, |
| 527 | + .dim = 1024, |
| 528 | + .metric = VecSimMetric_L2, |
| 529 | + .blockSize = 1024, |
| 530 | + /* SVS-Vamana specifics */ |
| 531 | + .quantBits = VecSimSvsQuant_NONE, |
| 532 | + .graph_max_degree = 63, // x^2-1 to round the graph block size |
| 533 | + .construction_window_size = 20, |
| 534 | + .max_candidate_pool_size = 1024, |
| 535 | + .prune_to = 60, |
| 536 | + .use_search_history = VecSimOption_ENABLE, |
| 537 | + }; |
| 538 | + VecSimParams index_params = {.algo = VecSimAlgo_SVS, .algoParams = {.svsParams = params}}; |
| 539 | + |
| 540 | + ASSERT_EXCEPTION_MESSAGE(SVSFactory::NewIndex(this->file_name, &index_params), std::runtime_error, |
| 541 | + std::string("Failed to open metadata file: ") + metadata_path.string()); |
| 542 | + |
| 543 | + // Create directory and metadata file with invalid encoding version |
| 544 | + std::filesystem::create_directories(this->file_name); |
| 545 | + std::ofstream output(metadata_path, std::ios::binary); |
| 546 | + |
| 547 | + // Write invalid encoding version (42) |
| 548 | + Serializer::writeBinaryPOD(output, 42); |
| 549 | + output.flush(); |
| 550 | + output.close(); |
| 551 | + |
| 552 | + ASSERT_EXCEPTION_MESSAGE(SVSFactory::NewIndex(this->file_name, &index_params), std::runtime_error, |
| 553 | + "Cannot load index: bad encoding version: 42"); |
| 554 | + |
| 555 | + // Clean up |
| 556 | + std::filesystem::remove_all(this->file_name); |
| 557 | +} |
| 558 | +#endif |
| 559 | + |
515 | 560 | struct logCtx {
|
516 | 561 | public:
|
517 | 562 | std::vector<std::string> logBuffer;
|
|
0 commit comments