Register IVF bindings into combined module
| 149 | if (!built_) { |
| 150 | throw std::runtime_error("IvfIndex must be built or loaded before save"); |
| 151 | } |
| 152 | index_->save(path.c_str()); |
| 153 | } |
| 154 | |
| 155 | static IvfIndex load(const std::string& path) { |
| 156 | IvfIndex wrapper; |
| 157 | wrapper.index_ = std::make_unique<rabitqlib::ivf::IVF>(); |
| 158 | wrapper.index_->load(path.c_str()); |
| 159 | wrapper.dim_ = wrapper.index_->dimension(); |
| 160 | wrapper.max_elements_ = wrapper.index_->max_elements(); |
| 161 | wrapper.num_clusters_ = wrapper.index_->num_clusters(); |
| 162 | wrapper.nbits_ = wrapper.index_->nbits(); |
| 163 | wrapper.metric_ = wrapper.index_->metric_type(); |
| 164 | wrapper.built_ = true; |
| 165 | return wrapper; |
| 166 | } |
| 167 | |
| 168 | [[nodiscard]] size_t dim() const { return dim_; } |
| 169 | [[nodiscard]] size_t max_elements() const { return max_elements_; } |
| 170 | [[nodiscard]] size_t num_clusters() const { return num_clusters_; } |
| 171 | [[nodiscard]] size_t nbits() const { return nbits_; } |
| 172 | [[nodiscard]] bool is_built() const { return built_; } |
| 173 | [[nodiscard]] std::string metric() const { return metric_to_string(metric_); } |
| 174 | |
| 175 | private: |
| 176 | IvfIndex() = default; |
| 177 | |
| 178 | size_t dim_ = 0; |
| 179 | size_t max_elements_ = 0; |
| 180 | size_t num_clusters_ = 0; |
| 181 | size_t nbits_ = 0; |
| 182 | rabitqlib::MetricType metric_ = rabitqlib::METRIC_L2; |
| 183 | bool built_ = false; |
| 184 | std::unique_ptr<rabitqlib::ivf::IVF> index_; |
no test coverage detected