jina.serve.executors package#

Submodules#

Module contents#

class jina.serve.executors.BaseExecutor(metas=None, requests=None, runtime_args=None, **kwargs)[source]#

Bases: JAMLCompatible

The base class of the executor, can be used to build encoder, indexer, etc.

Any executor inherited from BaseExecutor always has the meta defined in jina.executors.metas.defaults.

All arguments in the __init__() can be specified with a with map in the YAML config. Example:

class MyAwesomeExecutor:
    def __init__(awesomeness=5):
        pass

is equal to

jtype: MyAwesomeExecutor
with:
    awesomeness: 5

metas and requests are always auto-filled with values from YAML config.

Parameters
  • metas (Optional[Dict]) – a dict of metas fields

  • requests (Optional[Dict]) – a dict of endpoint-function mapping

  • runtime_args (Optional[Dict]) – a dict of arguments injected from Runtime during runtime

  • kwargs – additional extra keyword arguments to avoid failing when extra params ara passed that are not expected

close()[source]#

Always invoked as executor is destroyed.

You can write destructor & saving logic here.

Return type

None

property workspace: Optional[str]#

Get the workspace directory of the Executor.

Return type

Optional[str]

Returns

returns the workspace of the current shard of this Executor.

classmethod from_hub(uri, context=None, uses_with=None, uses_metas=None, uses_requests=None, **kwargs)[source]#

Construct an Executor from Hub.

Parameters
  • uri (str) – a hub Executor scheme starts with jinahub://

  • context (Optional[Dict[str, Any]]) – context replacement variables in a dict, the value of the dict is the replacement.

  • uses_with (Optional[Dict]) – dictionary of parameters to overwrite from the default config’s with field

  • uses_metas (Optional[Dict]) – dictionary of parameters to overwrite from the default config’s metas field

  • uses_requests (Optional[Dict]) – dictionary of parameters to overwrite from the default config’s requests field

  • kwargs – other kwargs accepted by the CLI jina hub pull

Return type

~T

Returns

the Hub Executor object.

from jina import Executor
from docarray import Document, DocumentArray

executor = Executor.from_hub(
    uri='jinahub://CLIPImageEncoder', install_requirements=True
)
classmethod serve(uses_with=None, uses_metas=None, uses_requests=None, stop_event=None, **kwargs)[source]#

Serve this Executor in a temporary Flow. Useful in testing an Executor in remote settings.

Parameters
  • uses_with (Optional[Dict]) – dictionary of parameters to overwrite from the default config’s with field

  • uses_metas (Optional[Dict]) – dictionary of parameters to overwrite from the default config’s metas field

  • uses_requests (Optional[Dict]) – dictionary of parameters to overwrite from the default config’s requests field

  • stop_event (Union[Event, Event, None]) – a threading event or a multiprocessing event that once set will resume the control Flow to main thread.

  • kwargs – other kwargs accepted by the Flow, full list can be found here <https://docs.jina.ai/api/jina.orchestrate.flow.base/>

class jina.serve.executors.ReducerExecutor(metas=None, requests=None, runtime_args=None, **kwargs)[source]#

Bases: BaseExecutor

ReducerExecutor is an Executor that performs a reduce operation on a matrix of DocumentArrays coming from shards. ReducerExecutor relies on DocumentArray.reduce_all to merge all DocumentArray into one DocumentArray which will be sent to the next deployment.

This Executor only adds a reduce endpoint to the BaseExecutor.

metas and requests are always auto-filled with values from YAML config.

Parameters
  • metas (Optional[Dict]) – a dict of metas fields

  • requests (Optional[Dict]) – a dict of endpoint-function mapping

  • runtime_args (Optional[Dict]) – a dict of arguments injected from Runtime during runtime

  • kwargs – additional extra keyword arguments to avoid failing when extra params ara passed that are not expected

reduce(docs_matrix=[], **kwargs)[source]#

Reduce docs_matrix into one DocumentArray using DocumentArray.reduce_all :type docs_matrix: List[ForwardRef] :param docs_matrix: a List of DocumentArrays to be reduced :param kwargs: extra keyword arguments :return: the reduced DocumentArray

requests = {'/default': <function ReducerExecutor.reduce>}#