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.
| 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. |
| 31 | py::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 |
no test coverage detected