| 91 | } |
| 92 | |
| 93 | TEST(FlatSearcher, NoBatch_FP32) { |
| 94 | std::mt19937 gen((std::random_device())()); |
| 95 | auto dist = std::uniform_real_distribution<float>(0.0f, 1.0f); |
| 96 | size_t dim = (std::uniform_int_distribution<size_t>(1, 512))(gen); |
| 97 | |
| 98 | IndexBuilder::Pointer builder = IndexFactory::CreateBuilder("FlatBuilder"); |
| 99 | ASSERT_NE(builder, nullptr); |
| 100 | |
| 101 | auto holder = std::make_shared<MultiPassIndexHolder<IndexMeta::DT_FP32>>(dim); |
| 102 | uint32_t document_count = |
| 103 | (std::uniform_int_distribution<size_t>(1, 10000))(gen); |
| 104 | for (uint32_t i = 0; i < document_count; i++) { |
| 105 | NumericalVector<float> vec(dim); |
| 106 | for (size_t j = 0; j < vec.size(); ++j) { |
| 107 | vec[j] = dist(gen) + static_cast<float>(i * 5); |
| 108 | } |
| 109 | ASSERT_TRUE(holder->emplace(i, vec)); |
| 110 | } |
| 111 | |
| 112 | IndexMeta meta1; |
| 113 | meta1.set_meta(IndexMeta::DataType::DT_FP32, dim); |
| 114 | meta1.set_metric("SquaredEuclidean", 0, Params()); |
| 115 | meta1.set_major_order(IndexMeta::MO_ROW); |
| 116 | BuildIndex(meta1, holder, INDEX_PATH + ".1"); |
| 117 | |
| 118 | IndexMeta meta2; |
| 119 | meta2.set_meta(IndexMeta::DataType::DT_FP32, dim); |
| 120 | meta2.set_metric("SquaredEuclidean", 0, Params()); |
| 121 | meta2.set_major_order(IndexMeta::MO_COLUMN); |
| 122 | BuildIndex(meta2, holder, INDEX_PATH + ".2"); |
| 123 | |
| 124 | IndexSearcher::Pointer searcher1, searcher2; |
| 125 | LoadIndex(INDEX_PATH + ".1", searcher1); |
| 126 | LoadIndex(INDEX_PATH + ".2", searcher2); |
| 127 | |
| 128 | auto context1 = searcher1->create_context(); |
| 129 | auto context2 = searcher2->create_context(); |
| 130 | auto context3 = searcher1->create_context(); |
| 131 | auto context4 = searcher2->create_context(); |
| 132 | auto context5 = searcher1->create_context(); |
| 133 | auto context6 = searcher2->create_context(); |
| 134 | uint32_t topk = std::min(10u, document_count); |
| 135 | context1->set_topk(topk); |
| 136 | context2->set_topk(topk); |
| 137 | context3->set_topk(topk); |
| 138 | context4->set_topk(topk); |
| 139 | context3->set_filter([](uint64_t) { return false; }); |
| 140 | context4->set_filter([](uint64_t) { return false; }); |
| 141 | context5->set_filter([](uint64_t) { return true; }); |
| 142 | context6->set_filter([](uint64_t) { return true; }); |
| 143 | |
| 144 | uint32_t query_count = (std::uniform_int_distribution<size_t>(1, 100))(gen); |
| 145 | for (uint32_t i = 0; i < query_count; i++) { |
| 146 | NumericalVector<float> vec(dim); |
| 147 | for (uint32_t j = 0; j < vec.size(); ++j) { |
| 148 | vec[j] = dist(gen); |
| 149 | } |
| 150 | ASSERT_EQ( |
nothing calls this directly
no test coverage detected