jina.optimizers.flow_runner module

class jina.optimizers.flow_runner.FlowRunner[source]

Bases: jina.jaml.JAMLCompatible

An abstract FlowRunner object in Jina.

run(trial_parameters, workspace='workspace', callback=None, **kwargs)[source]

Runs the defined Flow(s).

Parameters
  • trial_parameters (dict) – Parameters to be used as context

  • workspace (str) – Directory to be used for the flows

  • callback (Optional[Callable[…, None]]) – Callback that will be called by the Flows. Should store the evaluation results.

  • kwargs – Further arguments passed to the Flow(s) as context

Raises

NotImplementedErrorFlowRunner is just an interface. Please use any implemented subclass.

class jina.optimizers.flow_runner.SingleFlowRunner(flow_yaml, documents, request_size, execution_endpoint, overwrite_workspace=False)[source]

Bases: jina.optimizers.flow_runner.FlowRunner

SingleFlowRunner enables running a flow repeadetly with different context.

documents maps to a parameter of the execution_endpoint, depending on the method. If you use a generator function/list as documents, the default will work out of the box. Otherwise, the following settings will work:

For more reasonable values, have a look at the Flow.

Parameters
  • flow_yaml (str) – Path to Flow yaml

  • documents (Union[Iterable, str]) – Input parameter for execution_endpoint for iterating documents. (e.g. a list of documents for index or a .jsonlines file for index_lines)

  • request_size (int) – Request size used in the flow

  • execution_endpoint (str) – The endpoint, f.post(on=) should point to

  • overwrite_workspace (bool) – True, means workspace created by the Flow will be overwritten with each execution.

Raises

TypeError – When the documents are neither a str nor an Iterable

run(trial_parameters, workspace='workspace', callback=None, **kwargs)[source]

Running method of SingleFlowRunner.

Parameters
  • trial_parameters (dict) – parameters that need to be tried

  • workspace (str) – path of workspace

  • callback (Optional[Callable[…, None]]) – callback function

  • kwargs – keyword argument

class jina.optimizers.flow_runner.MultiFlowRunner(flows)[source]

Bases: jina.optimizers.flow_runner.FlowRunner

MultiFlowRunner chains and runs multiple Flows. It is an interface for common patterns like IndexFlow -> SearchFlow.

Parameters

flows (List[FlowRunner]) – Flows to be executed in sequence.

run(trial_parameters, workspace='workspace', callback=None, **kwargs)[source]

Running method of MultiFlowRunner.

Parameters
  • trial_parameters (dict) – parameters need to be tried

  • workspace (str) – path of workspace

  • callback (Optional[Callable[…, None]]) – callback function

  • kwargs – keyword argument