Skip to content

Docoarray protobuff convert int to float #391

@samsja

Description

@samsja

Context

When a DA is serialize then deserialize in protobuf, if the tags are int then there are converted to float.

This is an issue when using docarray with Jina. Especially for VectorDB indexer. For instance with the WeaviateIndexer:

from jina import Flow
from docarray import Document, DocumentArray

f = Flow().add(
    uses=WeaviateIndexer,
    uses_with={
        'name': 'Test',
        'n_dim': 3,
        'columns': [('price', 'int')],
    },
)

docs = DocumentArray(
    [
        Document(id=f'r{i}', embedding=np.random.rand(3), tags={'price': int(i)})
        for i in range(50)
    ]
)
with f:
        f.index(docs)

This will fail because the Weaviate backend expect the docs to have the tags price as int but the Executor will receive them as float because of the protobuff de/serialization.

code to reproduce:

see the following code to reproduce

from docarray import DocumentArray, Document


def test_type_protobuf():

    da_int = DocumentArray([Document(tags={'price': i}) for i in range(10)])
    da_receive = DocumentArray.from_protobuf(da_int.to_protobuf())

    for doc in da_receive:
        assert type(doc.tags['price']) == int

Output:

FAILED scratch_1.py::test_type_protobuf - AssertionError: assert <class 'float'> == int

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions