|
35 | 35 | from docarray.index.backends.helper import ( |
36 | 36 | _collect_query_args, |
37 | 37 | ) |
38 | | -from docarray.proto import DocProto, NdArrayProto, NodeProto |
| 38 | +from docarray.proto import DocProto |
39 | 39 | from docarray.typing.tensor.abstract_tensor import AbstractTensor |
40 | 40 | from docarray.typing.tensor.ndarray import NdArray |
41 | 41 | from docarray.utils._internal._typing import safe_issubclass |
@@ -571,16 +571,15 @@ def _doc_from_bytes( |
571 | 571 | ) -> BaseDoc: |
572 | 572 | schema = self.out_schema if out else self._schema |
573 | 573 | schema_cls = cast(Type[BaseDoc], schema) |
574 | | - pb = DocProto.FromString(data) |
| 574 | + pb = DocProto.FromString( |
| 575 | + data |
| 576 | + ) # I cannot reconstruct directly the DA object because it may fail at validation because embedding may not be Optional |
575 | 577 | for k, v in reconstruct_embeddings.items(): |
576 | | - nd_proto = NdArrayProto() |
577 | | - np_array = np.array(v) |
578 | | - nd_proto.dense.buffer = np_array.tobytes() |
579 | | - nd_proto.dense.ClearField('shape') |
580 | | - nd_proto.dense.shape.extend(list(np_array.shape)) |
581 | | - nd_proto.dense.dtype = np_array.dtype.str |
582 | | - node_proto = NodeProto(ndarray=nd_proto, type='ndarray') |
583 | | - |
| 578 | + node_proto = ( |
| 579 | + self.out_schema.__fields__[k] |
| 580 | + .type_._docarray_from_ndarray(np.array(v)) |
| 581 | + ._to_node_protobuf() |
| 582 | + ) |
584 | 583 | pb.data[k].MergeFrom(node_proto) |
585 | 584 |
|
586 | 585 | doc = schema_cls.from_protobuf(pb) |
|
0 commit comments