| 165 | } |
| 166 | |
| 167 | void ZVecPyParams::bind_index_params(pybind11::module_ &m) { |
| 168 | // binding base index params |
| 169 | py::class_<IndexParams, std::shared_ptr<IndexParams>> index_params( |
| 170 | m, "IndexParam", R"pbdoc( |
| 171 | Base class for all index parameter configurations. |
| 172 | |
| 173 | This abstract base class defines the common interface for index types. |
| 174 | It should not be instantiated directly; use derived classes instead. |
| 175 | |
| 176 | Attributes: |
| 177 | type (IndexType): The type of the index (e.g., HNSW, FLAT, INVERT). |
| 178 | )pbdoc"); |
| 179 | index_params |
| 180 | .def_property_readonly( |
| 181 | "type", |
| 182 | [](const IndexParams &self) -> IndexType { return self.type(); }, |
| 183 | "IndexType: The type of the index.") |
| 184 | .def("clone", &IndexParams::clone, py::return_value_policy::copy) |
| 185 | .def( |
| 186 | "__eq__", |
| 187 | [](const IndexParams &self, const py::object &other) { |
| 188 | if (!py::isinstance<IndexParams>(other)) return false; |
| 189 | return self == other.cast<const IndexParams &>(); |
| 190 | }, |
| 191 | py::is_operator()) |
| 192 | .def( |
| 193 | "to_dict", |
| 194 | [](const IndexParams &self) -> py::dict { |
| 195 | py::dict dict; |
| 196 | dict["type"] = index_type_to_string(self.type()); |
| 197 | return dict; |
| 198 | }, |
| 199 | "Convert to dictionary with all fields") |
| 200 | .def(py::pickle( |
| 201 | [](const IndexParams &self) { // __getstate__ |
| 202 | return py::make_tuple(self.type()); |
| 203 | }, |
| 204 | [](py::tuple t) { // __setstate__ |
| 205 | if (t.size() != 1) |
| 206 | throw std::runtime_error("Invalid state for IndexParams"); |
| 207 | return std::shared_ptr<IndexParams>(); |
| 208 | })); |
| 209 | |
| 210 | // binding invert index params |
| 211 | py::class_<InvertIndexParams, IndexParams, std::shared_ptr<InvertIndexParams>> |
| 212 | invert_params(m, "InvertIndexParam", R"pbdoc( |
| 213 | Parameters for configuring an invert index. |
| 214 | |
| 215 | This class controls whether range query |
| 216 | optimization is enabled for invert index structures. |
| 217 | |
| 218 | Attributes: |
| 219 | type (IndexType): Always `IndexType.INVERTED`. |
| 220 | enable_range_optimization (bool): Whether range optimization is enabled. |
| 221 | enable_extended_wildcard (bool): Whether extended wildcard (suffix and infix) search is enabled. |
| 222 | |
| 223 | Examples: |
| 224 | >>> params = InvertIndexParam(enable_range_optimization=True, enable_extended_wildcard=False) |
nothing calls this directly
no test coverage detected