| 131 | } |
| 132 | |
| 133 | void ZVecPyParams::bind_index_params(pybind11::module_ &m) { |
| 134 | // binding base index params |
| 135 | py::class_<IndexParams, std::shared_ptr<IndexParams>> index_params( |
| 136 | m, "IndexParam", R"pbdoc( |
| 137 | Base class for all index parameter configurations. |
| 138 | |
| 139 | This abstract base class defines the common interface for index types. |
| 140 | It should not be instantiated directly; use derived classes instead. |
| 141 | |
| 142 | Attributes: |
| 143 | type (IndexType): The type of the index (e.g., HNSW, FLAT, INVERT). |
| 144 | )pbdoc"); |
| 145 | index_params |
| 146 | .def_property_readonly( |
| 147 | "type", |
| 148 | [](const IndexParams &self) -> IndexType { return self.type(); }, |
| 149 | "IndexType: The type of the index.") |
| 150 | .def("clone", &IndexParams::clone, py::return_value_policy::copy) |
| 151 | .def( |
| 152 | "__eq__", |
| 153 | [](const IndexParams &self, const py::object &other) { |
| 154 | if (!py::isinstance<IndexParams>(other)) return false; |
| 155 | return self == other.cast<const IndexParams &>(); |
| 156 | }, |
| 157 | py::is_operator()) |
| 158 | .def( |
| 159 | "to_dict", |
| 160 | [](const IndexParams &self) -> py::dict { |
| 161 | py::dict dict; |
| 162 | dict["type"] = index_type_to_string(self.type()); |
| 163 | return dict; |
| 164 | }, |
| 165 | "Convert to dictionary with all fields") |
| 166 | .def(py::pickle( |
| 167 | [](const IndexParams &self) { // __getstate__ |
| 168 | return py::make_tuple(self.type()); |
| 169 | }, |
| 170 | [](py::tuple t) { // __setstate__ |
| 171 | if (t.size() != 1) |
| 172 | throw std::runtime_error("Invalid state for IndexParams"); |
| 173 | return std::shared_ptr<IndexParams>(); |
| 174 | })); |
| 175 | |
| 176 | // binding invert index params |
| 177 | py::class_<InvertIndexParams, IndexParams, std::shared_ptr<InvertIndexParams>> |
| 178 | invert_params(m, "InvertIndexParam", R"pbdoc( |
| 179 | Parameters for configuring an invert index. |
| 180 | |
| 181 | This class controls whether range query |
| 182 | optimization is enabled for invert index structures. |
| 183 | |
| 184 | Attributes: |
| 185 | type (IndexType): Always `IndexType.INVERTED`. |
| 186 | enable_range_optimization (bool): Whether range optimization is enabled. |
| 187 | enable_extended_wildcard (bool): Whether extended wildcard (suffix and infix) search is enabled. |
| 188 | |
| 189 | Examples: |
| 190 | >>> params = InvertIndexParam(enable_range_optimization=True, enable_extended_wildcard=False) |
nothing calls this directly
no test coverage detected