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

Method bind_vector_query

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

Source from the content-addressed store, hash-verified

2406}
2407
2408void ZVecPyParams::bind_vector_query(py::module_ &m) {
2409 // bind Fts
2410 py::class_<FtsClause>(m, "_Fts")
2411 .def(py::init<>())
2412 .def_readwrite("query_string", &FtsClause::query_string_)
2413 .def_readwrite("match_string", &FtsClause::match_string_)
2414 .def(py::pickle(
2415 [](const FtsClause &self) {
2416 return py::make_tuple(self.query_string_, self.match_string_);
2417 },
2418 [](py::tuple t) {
2419 if (t.size() != 2)
2420 throw std::runtime_error("Invalid pickle data for Fts");
2421 FtsClause obj{};
2422 obj.query_string_ = t[0].cast<std::string>();
2423 obj.match_string_ = t[1].cast<std::string>();
2424 return obj;
2425 }));
2426
2427 // Bind SubQuery (used by MultiQuery)
2428 py::class_<SubQuery>(m, "_SubQuery")
2429 .def(py::init<>())
2430 .def_readwrite("num_candidates", &SubQuery::num_candidates_)
2431 .def_static(
2432 "from_search_query",
2433 [](const SearchQuery &sq) {
2434 SubQuery sub;
2435 sub.num_candidates_ = sq.topk_;
2436 sub.target_ = sq.target_;
2437 // SubQuery is copied by value into MultiQuery. Materialize
2438 // non-owning vector views so the copied SubQuery does not depend on
2439 // the original _SearchQuery keep-alive relationship.
2440 if (auto *vvc = sub.target_.get_vector_view_clause()) {
2441 VectorClause vc{std::string(vvc->query_vector_),
2442 std::string(vvc->sparse_indices_),
2443 std::string(vvc->sparse_values_)};
2444 sub.target_.clause_ = std::move(vc);
2445 }
2446 return sub;
2447 },
2448 py::arg("search_query"),
2449 "Create a SubQuery from a single-target search query.");
2450
2451 // _SearchQuery is the Python class name; it wraps the
2452 // single-target SearchQuery so external Python code keeps working unchanged.
2453 py::class_<SearchQuery>(m, "_SearchQuery")
2454 .def(py::init<>())
2455 // properties
2456 .def_readwrite("topk", &SearchQuery::topk_)
2457 .def_property(
2458 "field_name",
2459 [](const SearchQuery &s) { return s.target_.field_name_; },
2460 [](SearchQuery &s, std::string v) {
2461 s.target_.field_name_ = std::move(v);
2462 })
2463 .def_readwrite("filter", &SearchQuery::filter_)
2464 .def_readwrite("include_vector", &SearchQuery::include_vector_)
2465 .def_property(

Callers

nothing calls this directly

Calls 9

set_query_vectorFunction · 0.85
is_sparse_vector_fieldFunction · 0.85
ToFP32Function · 0.85
to_stringFunction · 0.50
sizeMethod · 0.45
data_typeMethod · 0.45
emptyMethod · 0.45
dataMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected