| 1179 | } |
| 1180 | |
| 1181 | void ZVecPyParams::bind_query_params(py::module_ &m) { |
| 1182 | // binding base query params |
| 1183 | py::class_<QueryParams, std::shared_ptr<QueryParams>> query_params( |
| 1184 | m, "QueryParam", R"pbdoc( |
| 1185 | Base class for all query parameter configurations. |
| 1186 | |
| 1187 | This abstract base class defines common query settings such as search radius |
| 1188 | and whether to force linear (brute-force) search. It should not be instantiated |
| 1189 | directly; use derived classes like `HnswQueryParam` or `IVFQueryParam`. |
| 1190 | |
| 1191 | Attributes: |
| 1192 | type (IndexType): The index type this query is configured for. |
| 1193 | radius (float): Search radius for range queries. Used in combination with |
| 1194 | top-k to filter results. Default is 0.0 (disabled). |
| 1195 | is_linear (bool): If True, forces brute-force linear search instead of |
| 1196 | using the index. Useful for debugging or small datasets. Default is False. |
| 1197 | is_using_refiner (bool, optional): Whether to use refiner for the query. Default is False. |
| 1198 | )pbdoc"); |
| 1199 | query_params |
| 1200 | .def_property_readonly( |
| 1201 | "type", |
| 1202 | [](const QueryParams &self) -> IndexType { return self.type(); }, |
| 1203 | "IndexType: The type of index this query targets.") |
| 1204 | .def_property_readonly( |
| 1205 | "radius", |
| 1206 | [](const QueryParams &self) -> float { return self.radius(); }, |
| 1207 | "IndexType: The type of index this query targets.") |
| 1208 | .def_property_readonly( |
| 1209 | "is_linear", |
| 1210 | [](const QueryParams &self) -> bool { return self.is_linear(); }, |
| 1211 | "bool: Whether to bypass the index and use brute-force linear " |
| 1212 | "search.") |
| 1213 | .def_property_readonly( |
| 1214 | "is_using_refiner", |
| 1215 | [](const QueryParams &self) -> bool { |
| 1216 | return self.is_using_refiner(); |
| 1217 | }, |
| 1218 | "bool: Whether to use refiner for the query.") |
| 1219 | .def(py::pickle( |
| 1220 | [](const QueryParams &self) { // __getstate__ |
| 1221 | return py::make_tuple(self.type(), self.radius(), self.is_linear()); |
| 1222 | }, |
| 1223 | [](py::tuple t) { // __setstate__ |
| 1224 | if (t.size() != 3) |
| 1225 | throw std::runtime_error("Invalid state for QueryParams"); |
| 1226 | return std::shared_ptr<QueryParams>(); |
| 1227 | })); |
| 1228 | |
| 1229 | // binding hnsw query params |
| 1230 | py::class_<HnswQueryParams, QueryParams, std::shared_ptr<HnswQueryParams>> |
| 1231 | hnsw_params(m, "HnswQueryParam", R"pbdoc( |
| 1232 | Query parameters for HNSW (Hierarchical Navigable Small World) index. |
| 1233 | |
| 1234 | Controls the trade-off between search speed and accuracy via the `ef` parameter. |
| 1235 | |
| 1236 | Attributes: |
| 1237 | type (IndexType): Always ``IndexType.HNSW``. |
| 1238 | ef (int): Size of the dynamic candidate list during search. |
nothing calls this directly
no test coverage detected