Skip to content

Commit 4f6c270

Browse files
author
Joan Fontanals Martinez
committed
fix: reconstruct from proper type
1 parent 3f56d44 commit 4f6c270

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

docarray/index/backends/hnswlib.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -571,16 +571,15 @@ def _doc_from_bytes(
571571
) -> BaseDoc:
572572
schema = self.out_schema if out else self._schema
573573
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
575577
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_.from_ndarray(np.array(v))
581+
._to_node_protobuf()
582+
)
584583
pb.data[k].MergeFrom(node_proto)
585584

586585
doc = schema_cls.from_protobuf(pb)

0 commit comments

Comments
 (0)