Process via External Flow or Executor#
Tip
This feature requires the jina
dependency. Please install it by running pip install -U jina
.
You can call an external Flow/Sandbox/Executor to “process” a DocumentArray via post()
. The external Flow/Executor can be local, remote, or inside a Docker container.
For example, to process a DocumentArray with an existing Flow at 192.168.2.3
on port 12345
:
from docarray import DocumentArray
da = DocumentArray.empty(10)
r = da.post('grpc://192.168.2.3:12345')
r.summary()
You can also use any Executor from Executor Hub:
from docarray import DocumentArray, Document
da = DocumentArray([Document(text='Hi Alex, are you with your laptop?')])
r = da.post('jinahub+sandbox://CoquiTTS7', show_progress=True)
r.summary()
Documents Summary
Length 1
Homogenous Documents True
Common Attributes ('id', 'mime_type', 'text', 'uri')
Attributes Summary
Attribute Data type #Unique values Has empty value
──────────────────────────────────────────────────────────
id ('str',) 1 False
mime_type ('str',) 1 False
text ('str',) 1 False
uri ('str',) 1 False
Single Documents have syntactic sugar that leverages this processing, meaning you can also write the above example as follows:
from docarray import Document
d = Document(text='Hi Alex, are you with your laptop?')
r = d.post('jinahub+sandbox://CoquiTTS7')
Accept schemes#
post()
accepts a URI-like scheme, supporting a wide range of Flows/Hub Executors:
scheme://netloc[:port][/path]
Attribute |
Supported Values |
Meaning |
---|---|---|
|
1. One of |
|
2. One of |
Executor Hub Executor in source code/Docker container/sandbox |
|
|
1. Host address |
|
2. Hub Executor name |
Any Hub Executor |
|
3. Executor version (optional) |
e.g. |
|
|
e.g. |
|
|
e.g. |
Endpoint of Executor you want to call. |
Some examples:
.post('websocket://localhost:8081/foo')
: call the/foo
endpoint of the Flow atlocalhost
port8081
withwebsocket
protocol to process the DocumentArray; processing is local..post('grpc://192.168.12.2:12345/foo')
: call the/foo
endpoint of the Flow at192.168.12.2
port12345
withgrpc
protocol to process the DocumentArray; processing is remote..post('jinahub://Hello/foo')
: call the/foo
endpoint of the Hub ExecutorHello
to process the DocumentArray; processing is local..post('jinahub+sandbox://Hello/foo')
: call the/foo
endpoint of the Hub SandboxHello
to process the DocumentArray; processing is remote..post('jinahub+docker://Hello/v0.5.0/foo')
: call the/foo
endpoint of the Hub SandboxHello
of versionv0.5.0
to process the DocumentArray; processing in container.
Read more#
For a deeper explanation of Flow, Hub Executor and Sandbox, refer to Jina’s docs.