MCPcopy Create free account
hub / github.com/alibaba/zvec / bind_index_params

Method bind_index_params

src/binding/python/model/param/python_param.cc:131–1179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

index_type_to_stringFunction · 0.85
metric_type_to_stringFunction · 0.85
quantize_type_to_stringFunction · 0.85
initFunction · 0.85
metric_typeMethod · 0.80
total_bitsMethod · 0.80
sample_countMethod · 0.80
use_id_mapMethod · 0.80
n_listMethod · 0.80
n_itersMethod · 0.80

Tested by

no test coverage detected