|
18 | 18 |
|
19 | 19 | //! [Includes]
|
20 | 20 | // SVS Dependencies
|
21 |
| -#include "svs/orchestrators/vamana.h" // bulk of the dependencies required. |
22 |
| -#include "svs/core/recall.h" // Convenient k-recall@n computation. |
| 21 | +#include "svs/orchestrators/vamana.h" // bulk of the dependencies required. |
| 22 | +#include "svs/core/recall.h" // Convenient k-recall@n computation. |
| 23 | +#include "svs/extensions/vamana/scalar.h" // SQ vamana extensions. |
| 24 | +#include "svs/quantization/scalar/scalar.h" // SQ implementation. |
23 | 25 |
|
24 | 26 | // Alternative main definition
|
25 | 27 | #include "svsmain.h"
|
@@ -51,7 +53,7 @@ double run_recall(
|
51 | 53 | }
|
52 | 54 |
|
53 | 55 | const bool DEBUG = false;
|
54 |
| -void check(double expected, double got, double eps = 0.001) { |
| 56 | +void check(double expected, double got, double eps = 0.005) { |
55 | 57 | double diff = std::abs(expected - got);
|
56 | 58 | if constexpr (DEBUG) {
|
57 | 59 | fmt::print("Expected {}. Got {}\n", expected, got);
|
@@ -156,6 +158,36 @@ int svs_main(std::vector<std::string> args) {
|
156 | 158 | index.set_threadpool(svs::threads::DefaultThreadPool(4));
|
157 | 159 | //! [Set a new thread pool with n-threads]
|
158 | 160 |
|
| 161 | + //! [Compressed Loader] |
| 162 | + // Quantization |
| 163 | + namespace scalar = svs::quantization::scalar; |
| 164 | + |
| 165 | + // Wrap the compressor object in a lazy functor. |
| 166 | + // This will defer loading and compression of the SQ dataset until the threadpool |
| 167 | + // used in the index has been created. |
| 168 | + auto compressor = svs::lib::Lazy([=](svs::threads::ThreadPool auto& threadpool) { |
| 169 | + auto data = svs::VectorDataLoader<float, 128>("example_data").load(); |
| 170 | + return scalar::SQDataset<std::int8_t, 128>::compress(data, threadpool); |
| 171 | + }); |
| 172 | + index = svs::Vamana::assemble<float>( |
| 173 | + "example_config", |
| 174 | + svs::GraphLoader("example_graph"), |
| 175 | + compressor, |
| 176 | + svs::DistanceType::L2, |
| 177 | + 4 |
| 178 | + ); |
| 179 | + recall = run_recall(index, queries, groundtruth, 30, 10, "Compressed load"); |
| 180 | + check(0.8190, recall); |
| 181 | + //! [Compressed Loader] |
| 182 | + |
| 183 | + //! [Build Index Compressed] |
| 184 | + // Compressed building |
| 185 | + index = |
| 186 | + svs::Vamana::build<float>(parameters, compressor, svs::DistanceL2(), num_threads); |
| 187 | + recall = run_recall(index, queries, groundtruth, 30, 10, "Compressed Build"); |
| 188 | + check(0.8212, recall); |
| 189 | + //! [Build Index Compressed] |
| 190 | + |
159 | 191 | return 0;
|
160 | 192 | }
|
161 | 193 |
|
|
0 commit comments