jina-ai / jina

☁️ Build multimodal AI applications with cloud-native stack
https://docs.jina.ai
Apache License 2.0
20.64k stars 2.21k forks source link

make gRPC DocumentArrayProto in Java #5280

Closed fishfl closed 1 year ago

fishfl commented 1 year ago

I want to use the gRPC protocol with a language other than Python.

so I follow the instruction (https://docs.jina.ai/fundamentals/client/third-party-client/):

"Download the two proto definition files: jina.proto and docarray.proto from github (be sure to use the latest release branch) Compile them with protoc and precise to which programming language you want to compile them. Add the generated files to your project and import them in your code. You should finally be able to communicate with your Flow using the gRPC protocol. You can find more information on the gRPC message and service that you can use to communicate in the Protobuf documentation. "

I generate the Java class with proto files. But It didn't say how to build the proto DocumentArrayProto! Docarray.DocumentArrayProto da = Docarray.DocumentArrayProto.parseFrom("byte array here") "byte array here" for what? what's the format of the string? Or I should use the builder? And how? Please show me some example on how to build the DocumentArrayProto with the given data like: text image tensor ...

Thanks!

JoanFM commented 1 year ago

The idea is that you understand how to build your DocumentArrayProto from theproto class created and understand how to create these objects. We cannot add examples on all the possible languages, we will add some examples for Go and Kotlin done by community soon that we hope can serve as inspiration.

fishfl commented 1 year ago

The idea is that you understand how to build your DocumentArrayProto from theproto class created and understand how to create these objects. We cannot add examples on all the possible languages, we will add some examples for Go and Kotlin done by community soon that we hope can serve as inspiration.

Yes, but I have nothing to follow, the proto is defined like this:

message DocumentArrayProto {

}

There's nothing in it. so is the Java class 'Docarray.DocumentArrayProto'

If I want to build a DocmentArray in python is easy: da = DocumentArray([Document(text='hello'), Document(text='world')])

But in 'Docarray.DocumentArrayProto', I have nothing to use. Few method to create the content of DocumentArrayProto. There's no parameter to set the 'hello' and 'world'.

JoanFM commented 1 year ago

Hello @fishfl ,

This is because the DocumentArrayProto does not come directly from Jina but from docarray package. This way Jina can work with different versions of the library.

You can check it here:

https://github.com/jina-ai/docarray/blob/main/docarray/proto/docarray.proto

fishfl commented 1 year ago

Hello @fishfl ,

This is because the DocumentArrayProto does not come directly from Jina but from docarray package. This way Jina can work with different versions of the library.

You can check it here:

https://github.com/jina-ai/docarray/blob/main/docarray/proto/docarray.proto

It works! Thanks a lot~

JoanFM commented 1 year ago

Hey @fishfl,

Glad to hear that. Are you building some Jina Client for Java? In case it is the case, would it be open sourced?