| 84 | } |
| 85 | |
| 86 | void ZVecPySchemas::bind_collection_schema(py::module_ &m) { |
| 87 | py::class_<CollectionSchema, CollectionSchema::Ptr>(m, "_CollectionSchema") |
| 88 | .def(py::init<const std::string &, const FieldSchemaPtrList &>(), |
| 89 | py::arg("name"), py::arg("fields"), |
| 90 | "Construct with name and list of fields") |
| 91 | .def_property_readonly("name", &CollectionSchema::name) |
| 92 | .def("has_field", &CollectionSchema::has_field, py::arg("field_name"), |
| 93 | "Check if a field exists.") |
| 94 | .def( |
| 95 | "get_field", |
| 96 | [](const CollectionSchema &self, const std::string &name) |
| 97 | -> const FieldSchema * { return self.get_field(name); }, |
| 98 | py::arg("field_name"), py::return_value_policy::reference_internal, |
| 99 | "Get field by name (const pointer), returns None if not found.") |
| 100 | .def( |
| 101 | "get_forward_field", |
| 102 | [](const CollectionSchema &self, const std::string &name) |
| 103 | -> const FieldSchema * { return self.get_forward_field(name); }, |
| 104 | py::arg("field_name"), py::return_value_policy::reference_internal, |
| 105 | "Get forward field (used for filtering).") |
| 106 | .def( |
| 107 | "get_vector_field", |
| 108 | [](const CollectionSchema &self, const std::string &name) |
| 109 | -> const FieldSchema * { return self.get_vector_field(name); }, |
| 110 | py::arg("field_name"), py::return_value_policy::reference_internal, |
| 111 | "Get vector field by name.") |
| 112 | .def("fields", &CollectionSchema::fields, |
| 113 | "Return list of all field schemas.", py::return_value_policy::copy) |
| 114 | .def("forward_fields", &CollectionSchema::forward_fields, |
| 115 | "Return list of forward-indexed fields.", |
| 116 | py::return_value_policy::copy) |
| 117 | .def("vector_fields", &CollectionSchema::vector_fields, |
| 118 | "Return list of vector fields.", py::return_value_policy::copy) |
| 119 | .def("__eq__", &CollectionSchema::operator==) |
| 120 | .def("__ne__", &CollectionSchema::operator!=) |
| 121 | .def(py::pickle( |
| 122 | [](const CollectionSchema &cs) { |
| 123 | return py::make_tuple(cs.name(), cs.fields(), |
| 124 | cs.max_doc_count_per_segment()); |
| 125 | }, |
| 126 | [](py::tuple t) { |
| 127 | if (t.size() != 3) |
| 128 | throw std::runtime_error("Invalid state for CollectionSchema!"); |
| 129 | |
| 130 | auto name = t[0].cast<std::string>(); |
| 131 | auto fields = t[1].cast<FieldSchemaPtrList>(); |
| 132 | auto max_docs = t[2].cast<uint64_t>(); |
| 133 | |
| 134 | auto cs = std::make_shared<CollectionSchema>(name, fields); |
| 135 | cs->set_max_doc_count_per_segment(max_docs); |
| 136 | return cs; |
| 137 | })); |
| 138 | } |
| 139 | |
| 140 | void ZVecPySchemas::bind_collection_stats(py::module_ &m) { |
| 141 | pybind11::class_<CollectionStats>(m, "CollectionStats") |
nothing calls this directly
no test coverage detected