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

Function docs_to_tuples

src/binding/python/model/python_collection.cc:31–45  ·  view source on GitHub ↗

Batch-materialize a DocPtrList into a list of (id, score, fields, vectors) tuples in a single GIL-held section, avoiding per-doc _Doc wrappers and per-doc Python->C++ crossings on the hot query path. The forward/vector field lists are resolved once per batch rather than once per doc.

Source from the content-addressed store, hash-verified

29// per-doc Python->C++ crossings on the hot query path. The forward/vector field
30// lists are resolved once per batch rather than once per doc.
31py::list docs_to_tuples(const DocPtrList &docs,
32 const CollectionSchema &schema) {
33 const auto forward_fields = schema.forward_fields();
34 const auto vector_fields = schema.vector_fields();
35 py::list out(docs.size());
36 for (size_t i = 0; i < docs.size(); ++i) {
37 if (docs[i]) {
38 out[i] = ZVecPyDoc::doc_to_tuple_with_fields(*docs[i], forward_fields,
39 vector_fields);
40 } else {
41 out[i] = py::none();
42 }
43 }
44 return out;
45}
46
47} // namespace
48

Callers 1

execute_for_pythonFunction · 0.85

Calls 3

forward_fieldsMethod · 0.80
vector_fieldsMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected