| 22 | #include "vsag/vsag.h" |
| 23 | |
| 24 | int |
| 25 | main() { |
| 26 | vsag::Options::Instance().logger()->SetLevel(vsag::Logger::kINFO); |
| 27 | |
| 28 | /******************* Customize Thread Pool *****************/ |
| 29 | auto pool = vsag::Engine::CreateThreadPool(16).value(); |
| 30 | auto allocator = vsag::Engine::CreateDefaultAllocator(); |
| 31 | vsag::Resource resource(allocator.get(), pool.get()); |
| 32 | vsag::Engine engine(&resource); |
| 33 | |
| 34 | vsag::init(); |
| 35 | |
| 36 | /******************* Prepare Base Dataset *****************/ |
| 37 | int64_t num_vectors = 1000; |
| 38 | int64_t dim = 128; |
| 39 | auto ids = new int64_t[num_vectors]; |
| 40 | auto vectors = new float[dim * num_vectors]; |
| 41 | |
| 42 | std::mt19937 rng; |
| 43 | rng.seed(47); |
| 44 | std::uniform_real_distribution<> distrib_real; |
| 45 | for (int64_t i = 0; i < num_vectors; ++i) { |
| 46 | ids[i] = i; |
| 47 | } |
| 48 | for (int64_t i = 0; i < dim * num_vectors; ++i) { |
| 49 | vectors[i] = distrib_real(rng); |
| 50 | } |
| 51 | auto base = vsag::Dataset::Make(); |
| 52 | base->NumElements(num_vectors)->Dim(dim)->Ids(ids)->Float32Vectors(vectors); |
| 53 | |
| 54 | /******************* Create DiskANN Index *****************/ |
| 55 | auto diskann_build_paramesters = R"( |
| 56 | { |
| 57 | "dtype": "float32", |
| 58 | "metric_type": "l2", |
| 59 | "dim": 128, |
| 60 | "diskann": { |
| 61 | "max_degree": 16, |
| 62 | "ef_construction": 200, |
| 63 | "pq_sample_rate": 0.5, |
| 64 | "pq_dims": 9, |
| 65 | "use_pq_search": true, |
| 66 | "use_async_io": false, |
| 67 | "use_bsa": true |
| 68 | } |
| 69 | } |
| 70 | )"; |
| 71 | auto index = engine.CreateIndex("diskann", diskann_build_paramesters).value(); |
| 72 | |
| 73 | /******************* Build DiskANN Index *****************/ |
| 74 | if (auto build_result = index->Build(base); build_result.has_value()) { |
| 75 | std::cout << "After Build(), Index DiskANN contains: " << index->GetNumElements() |
| 76 | << std::endl; |
| 77 | } else if (build_result.error().type == vsag::ErrorType::INTERNAL_ERROR) { |
| 78 | std::cerr << "Failed to build index: internalError" << std::endl; |
| 79 | exit(-1); |
| 80 | } |
| 81 |
nothing calls this directly
no test coverage detected