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

Method bind_options

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

Source from the content-addressed store, hash-verified

2074}
2075
2076void ZVecPyParams::bind_options(py::module_ &m) { // binding collection options
2077 py::class_<CollectionOptions>(m, "CollectionOption", R"pbdoc(
2078Options for opening or creating a collection.
2079
2080Attributes:
2081 read_only (bool): Whether the collection is opened in read-only mode.
2082 Default is False.
2083 enable_mmap (bool): Whether to use memory-mapped I/O for data files.
2084 Default is True.
2085
2086Examples:
2087 >>> opt = CollectionOption(read_only=True, enable_mmap=False)
2088 >>> print(opt.read_only)
2089 True
2090)pbdoc")
2091 .def(py::init<bool, bool>(), py::arg("read_only") = false,
2092 py::arg("enable_mmap") = true,
2093 R"pbdoc(
2094Constructs a CollectionOption instance.
2095
2096Args:
2097 read_only (bool, optional): Open collection in read-only mode.
2098 Defaults to False.
2099 enable_mmap (bool, optional): Enable memory-mapped I/O.
2100 Defaults to True.
2101)pbdoc")
2102 .def_property_readonly(
2103 "enable_mmap",
2104 [](const CollectionOptions &self) { return self.enable_mmap_; })
2105 .def_property_readonly(
2106 "read_only",
2107 [](const CollectionOptions &self) { return self.read_only_; })
2108 .def("__repr__",
2109 [](const CollectionOptions &self) -> std::string {
2110 return "{"
2111 "\"enable_mmap\":" +
2112 std::to_string(self.enable_mmap_) +
2113 ", \"read_only\":" + std::to_string(self.read_only_) + "}";
2114 })
2115 .def(py::pickle(
2116 [](const CollectionOptions &self) {
2117 return py::make_tuple(self.read_only_, self.enable_mmap_,
2118 self.max_buffer_size_);
2119 },
2120 [](py::tuple t) {
2121 if (t.size() != 3)
2122 throw std::runtime_error(
2123 "Invalid pickle data for CollectionOptions");
2124 CollectionOptions obj{};
2125 obj.read_only_ = t[0].cast<bool>();
2126 obj.enable_mmap_ = t[1].cast<bool>();
2127 obj.max_buffer_size_ = t[2].cast<uint32_t>();
2128 return obj;
2129 }));
2130
2131 // SegmentOptions
2132 py::class_<SegmentOptions>(m, "SegmentOption", R"pbdoc(
2133Options for segment-level operations.

Callers

nothing calls this directly

Calls 2

to_stringFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected