Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/user_guide/sending/send_docvec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Serialization for `DocVec`
When sending or storing `DocVec`, you need to use serialization. `DocVec` only supports protobuf to serialize the data.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
When sending or storing `DocVec`, you need to use serialization. `DocVec` only supports protobuf to serialize the data.
When sending or storing [`DocVec`][docarray.array.doc_vec.doc_vec.DocVec], you need to use serialization. `DocVec` only supports protobuf to serialize the data.

You can use `to_protobuf()` and `from_protobuf()` to serialize and deserialize a `DocVec`

```python
import numpy as np

from docarray import BaseDoc, DocVec
from docarray.typing import AnyTensor


class SimpleVecDoc(BaseDoc):
tensor: AnyTensor


dv = DocVec[SimpleVecDoc]([SimpleVecDoc(tensor=np.ones(16)) for _ in range(8)])

proto_message_dv = dv.to_protobuf()

dv_from_proto = DocVec[SimpleVecDoc].from_protobuf(proto_message_dv)
```

`to_protobuf()` returns a protobuf object of `docarray_pb2.DocVecProto` class. `from_protobuf()` accepts a protobuf message object to construct a `DocVec`.