Skip to content

Commit 2efa744

Browse files
committed
feat(cpp): add make_searcher overloads accepting the DynamicExplorationGraph facade
1 parent 44bcf85 commit 2efa744

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

‎cpp/deglib/include/deglib/deglib.h‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,25 @@ inline DynamicExplorationGraph load_mutable_graph(const char* path_graph, const
115115
return DynamicExplorationGraph(std::move(graph));
116116
}
117117

118+
/**
119+
* Create a high-performance Searcher over a DynamicExplorationGraph facade.
120+
* Convenience overloads that forward to deglib::search::make_searcher using the graph's internal representation,
121+
* so end users can pass the public graph type directly.
122+
*/
123+
inline std::unique_ptr<deglib::search::SearcherBase> make_searcher(const DynamicExplorationGraph& graph) {
124+
return deglib::search::make_searcher(graph.internal());
125+
}
126+
127+
template <typename QuantT>
128+
requires deglib::quantization::Quantizer<QuantT>
129+
inline std::unique_ptr<deglib::search::SearcherBase> make_searcher(const DynamicExplorationGraph& graph, QuantT quantizer) {
130+
return deglib::search::make_searcher(graph.internal(), std::move(quantizer));
131+
}
132+
133+
template <typename QuantT, typename RefinerT>
134+
requires(deglib::quantization::Quantizer<QuantT> || std::is_same_v<QuantT, deglib::search::NoQuantizer>)
135+
inline std::unique_ptr<deglib::search::SearcherBase> make_searcher(const DynamicExplorationGraph& graph, QuantT quantizer, RefinerT refiner) {
136+
return deglib::search::make_searcher(graph.internal(), std::move(quantizer), std::move(refiner));
137+
}
138+
118139
} // namespace deglib

‎cpp/test/src/unit/test_searcher.cpp‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// test_searcher.cpp — Unit tests for deglib::search::Searcher (searcher.h)
22

33
#include "deglib/builder.h"
4+
#include "deglib/deglib.h"
45
#include "deglib/distances.h"
56
#include "deglib/graph.h"
67
#include "deglib/optimization.h"
@@ -47,6 +48,27 @@ TEST(SearcherTest, DirectFP32Search) {
4748
EXPECT_NEAR(span_res.distances[0], 0.0f, 1e-5f);
4849
}
4950

51+
TEST(SearcherTest, MakeSearcherAcceptsFacade) {
52+
const uint32_t dim = 4;
53+
const uint32_t count = 20;
54+
55+
std::vector<float> data(count * dim);
56+
for (size_t i = 0; i < data.size(); ++i) {
57+
data[i] = static_cast<float>(i * 1.5f + 0.1f);
58+
}
59+
60+
auto graph = deglib::builder::build_from_data(std::span<const float>(data), dim, {}, 8, deglib::distances::Metric::FP32_L2);
61+
62+
// The facade-level overload accepts a DynamicExplorationGraph directly (no .internal() bridge needed).
63+
auto searcher = deglib::make_searcher(graph);
64+
ASSERT_NE(searcher, nullptr);
65+
66+
auto res = searcher->search(std::span<const float>(data.data(), dim), 5, 0.1f, 1.0f, /*return_distances=*/true);
67+
EXPECT_EQ(res.size(), 5u);
68+
EXPECT_EQ(res.indices[0], 0u);
69+
EXPECT_NEAR(res.distances[0], 0.0f, 1e-5f);
70+
}
71+
5072
TEST(SearcherTest, QuantizedInt8WithFP16Refiner) {
5173
const uint32_t dim = 8;
5274
const uint32_t count = 50;

0 commit comments

Comments
 (0)