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

Method bind_query_params

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

Source from the content-addressed store, hash-verified

1292}
1293
1294void ZVecPyParams::bind_query_params(py::module_ &m) {
1295 // binding base query params
1296 py::class_<QueryParams, std::shared_ptr<QueryParams>> query_params(
1297 m, "QueryParam", R"pbdoc(
1298Base class for all query parameter configurations.
1299
1300This abstract base class defines common query settings such as search radius
1301and whether to force linear (brute-force) search. It should not be instantiated
1302directly; use derived classes like `HnswQueryParam` or `IVFQueryParam`.
1303
1304Attributes:
1305 type (IndexType): The index type this query is configured for.
1306 radius (float): Search radius for range queries. Used in combination with
1307 top-k to filter results. Default is 0.0 (disabled).
1308 is_linear (bool): If True, forces brute-force linear search instead of
1309 using the index. Useful for debugging or small datasets. Default is False.
1310 is_using_refiner (bool, optional): Whether to use refiner for the query. Default is False.
1311)pbdoc");
1312 query_params
1313 .def_property_readonly(
1314 "type",
1315 [](const QueryParams &self) -> IndexType { return self.type(); },
1316 "IndexType: The type of index this query targets.")
1317 .def_property_readonly(
1318 "radius",
1319 [](const QueryParams &self) -> float { return self.radius(); },
1320 "IndexType: The type of index this query targets.")
1321 .def_property_readonly(
1322 "is_linear",
1323 [](const QueryParams &self) -> bool { return self.is_linear(); },
1324 "bool: Whether to bypass the index and use brute-force linear "
1325 "search.")
1326 .def_property_readonly(
1327 "is_using_refiner",
1328 [](const QueryParams &self) -> bool {
1329 return self.is_using_refiner();
1330 },
1331 "bool: Whether to use refiner for the query.")
1332 .def(py::pickle(
1333 [](const QueryParams &self) { // __getstate__
1334 return py::make_tuple(self.type(), self.radius(), self.is_linear());
1335 },
1336 [](py::tuple t) { // __setstate__
1337 if (t.size() != 3)
1338 throw std::runtime_error("Invalid state for QueryParams");
1339 return std::shared_ptr<QueryParams>();
1340 }));
1341
1342 // binding hnsw query params
1343 py::class_<HnswQueryParams, QueryParams, std::shared_ptr<HnswQueryParams>>
1344 hnsw_params(m, "HnswQueryParam", R"pbdoc(
1345Query parameters for HNSW (Hierarchical Navigable Small World) index.
1346
1347Controls the trade-off between search speed and accuracy via the `ef` parameter.
1348
1349Attributes:
1350 type (IndexType): Always ``IndexType.HNSW``.
1351 ef (int): Size of the dynamic candidate list during search.

Callers

nothing calls this directly

Calls 10

initFunction · 0.85
index_type_to_stringFunction · 0.85
nprobeMethod · 0.80
list_sizeMethod · 0.80
to_stringFunction · 0.50
typeMethod · 0.45
sizeMethod · 0.45
containsMethod · 0.45
efMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected