2424#include " svs/orchestrators/exhaustive.h"
2525#include " svs/orchestrators/vamana.h"
2626
27-
2827int main () {
29- // STEP 1: Compress Data with LeanVec, reducing dimensionality to leanvec_dim dimensions and using
30- // 4 and 8 bits for primary and secondary levels respectively.
31- // ! [Compress data]
28+ // STEP 1: Compress Data with LeanVec, reducing dimensionality to leanvec_dim dimensions
29+ // and using 4 and 8 bits for primary and secondary levels respectively.
30+ // ! [Compress data]
3231 const size_t num_threads = 4 ;
3332 size_t padding = 32 ;
3433 size_t leanvec_dim = 64 ;
3534 auto threadpool = svs::threads::as_threadpool (num_threads);
36- auto loaded = svs::VectorDataLoader<float >(std::filesystem::path (SVS_DATA_DIR) / " data_f32.svs" ).load ();
37- auto data = svs::leanvec::LeanDataset<svs::leanvec::UsingLVQ<4 >, svs::leanvec::UsingLVQ<8 >, svs::Dynamic, svs::Dynamic>::reduce (
38- loaded, std::nullopt , threadpool, padding, svs::lib::MaybeStatic<svs::Dynamic>(leanvec_dim)
39- );
35+ auto loaded =
36+ svs::VectorDataLoader<float >(std::filesystem::path (SVS_DATA_DIR) / " data_f32.svs" )
37+ .load ();
38+ auto data = svs::leanvec::LeanDataset<
39+ svs::leanvec::UsingLVQ<4 >,
40+ svs::leanvec::UsingLVQ<8 >,
41+ svs::Dynamic,
42+ svs::Dynamic>::
43+ reduce (
44+ loaded,
45+ std::nullopt ,
46+ threadpool,
47+ padding,
48+ svs::lib::MaybeStatic<svs::Dynamic>(leanvec_dim)
49+ );
4050 // ! [Compress data]
4151
42-
43- // STEP 2: Build Vamana Index
52+ // STEP 2: Build Vamana Index
4453 // ! [Index Build]
4554 auto parameters = svs::index::vamana::VamanaBuildParameters{};
46- svs::Vamana index = svs::Vamana::build<float >(parameters, data, svs::distance::DistanceL2 (), num_threads);
55+ svs::Vamana index = svs::Vamana::build<float >(
56+ parameters, data, svs::distance::DistanceL2 (), num_threads
57+ );
4758 // ! [Index Build]
4859
4960 // STEP 3: Search the Index
@@ -52,12 +63,15 @@ int main() {
5263 const size_t n_neighbors = 10 ;
5364 index.set_search_window_size (search_window_size);
5465
55- auto queries = svs::load_data<float >(std::filesystem::path (SVS_DATA_DIR) / " queries_f32.fvecs" );
66+ auto queries =
67+ svs::load_data<float >(std::filesystem::path (SVS_DATA_DIR) / " queries_f32.fvecs" );
5668 auto results = index.search (queries, n_neighbors);
5769 // ! [Perform Queries]
5870
5971 // ! [Recall]
60- auto groundtruth = svs::load_data<int >(std::filesystem::path (SVS_DATA_DIR) / " groundtruth_euclidean.ivecs" );
72+ auto groundtruth = svs::load_data<int >(
73+ std::filesystem::path (SVS_DATA_DIR) / " groundtruth_euclidean.ivecs"
74+ );
6175 double recall = svs::k_recall_at_n (groundtruth, results, n_neighbors, n_neighbors);
6276
6377 fmt::print (" Recall@{} = {:.4f}\n " , n_neighbors, recall);
@@ -66,15 +80,22 @@ int main() {
6680 // STEP 4: Saving and reloading the index
6781 // ! [Saving Loading]
6882 index.save (" config" , " graph" , " data" );
69- index = svs::Vamana::assemble<float >(
70- " config" , svs::GraphLoader (" graph" ), svs::lib::load_from_disk<svs::leanvec::LeanDataset<svs::leanvec::UsingLVQ<4 >, svs::leanvec::UsingLVQ<8 >, svs::Dynamic, svs::Dynamic>>(" data" , padding), svs::distance::DistanceL2 (), num_threads
83+ index = svs::Vamana::assemble<float >(
84+ " config" ,
85+ svs::GraphLoader (" graph" ),
86+ svs::lib::load_from_disk<svs::leanvec::LeanDataset<
87+ svs::leanvec::UsingLVQ<4 >,
88+ svs::leanvec::UsingLVQ<8 >,
89+ svs::Dynamic,
90+ svs::Dynamic>>(" data" , padding),
91+ svs::distance::DistanceL2 (),
92+ num_threads
7193 );
7294 // ! [Saving Loading]
7395 index.set_search_window_size (search_window_size);
7496 recall = svs::k_recall_at_n (groundtruth, results, n_neighbors, n_neighbors);
7597
7698 fmt::print (" Recall@{} after saving and reloading = {:.4f}\n " , n_neighbors, recall);
7799
78-
79100 return 0 ;
80101}
0 commit comments