YAML specification#

To generate a YAML configuration from an Orchestration, use save_config().

YAML completion in IDE#

We provide a JSON Schema for your IDE to enable code completion, syntax validation, members listing and displaying help text.

PyCharm users#

  1. Click menu Preferences -> JSON Schema mappings;

  2. Add a new schema, in the Schema File or URL write https://schemas.jina.ai/schemas/latest.json; select JSON Schema Version 7;

  3. Add a file path pattern and link it to *.jaml or *.jina.yml or any suffix you commonly used for Jina Flow’s YAML.

VSCode users#

  1. Install the extension: YAML Language Support by Red Hat;

  2. In IDE-level settings.json add:

"yaml.schemas": {
    "https://schemas.jina.ai/schemas/latest.json": ["/*.jina.yml", "/*.jaml"],
}

You can bind Schema to any file suffix you commonly used for Jina Flow’s YAML.

Example YAML#

jtype: Deployment
version: '1'
with:
  protocol: http
name: firstexec
uses:
  jtype: MyExec
  py_modules:
    - executor.py
jtype: Flow
version: '1'
with:
  protocol: http
executors:
# inline Executor YAML
- name: firstexec
  uses:
    jtype: MyExec
    py_modules:
      - executor.py
# reference to Executor YAML
- name: secondexec
  uses: indexer.yml
  workspace: /home/my/workspace
# reference to Executor Python class
- name: thirdexec
  uses: CustomExec  # located in executor.py

Fields#

jtype#

String that is always set to either “Flow” or “Deployment”, indicating the corresponding Python class.

version#

String indicating the version of the Flow or Deployment.

with#

Keyword arguments are passed to a Flow’s __init__() method. You can set Flow-specific arguments and Gateway-specific arguments here:

Orchestration arguments#

Name

Description

Type

Default

name

The name of this object.

This will be used in the following places:
- how you refer to this object in Python/YAML/CLI
- visualization
- log message header
- …

When not given, then the default naming strategy will apply.

string

None

workspace

The working directory for any IO operations in this object. If not set, then derive from its parent workspace.

string

None

log_config

The config name or the absolute path to the YAML config file of the logger used in this object.

string

default

quiet

If set, then no log will be emitted from this object.

boolean

False

quiet_error

If set, then exception stack information will not be added to the log

boolean

False

suppress_root_logging

If set, then no root handlers will be suppressed from logging.

boolean

False

uses

The YAML path represents a flow. It can be either a local file path or a URL.

string

None

reload

If set, auto-reloading on file changes is enabled: the Flow will restart while blocked if YAML configuration source is changed. This also applies apply to underlying Executors, if their source code or YAML configuration has changed.

boolean

False

env

The map of environment variables that are available inside runtime

object

None

inspect

The strategy on those inspect deployments in the flow.

If REMOVE is given then all inspect deployments are removed when building the flow.

string

COLLECT

Name

Description

Type

Default

name

The name of this object.

This will be used in the following places:
- how you refer to this object in Python/YAML/CLI
- visualization
- log message header
- …

When not given, then the default naming strategy will apply.

string

None

workspace

The working directory for any IO operations in this object. If not set, then derive from its parent workspace.

string

None

log_config

The config name or the absolute path to the YAML config file of the logger used in this object.

string

default

quiet

If set, then no log will be emitted from this object.

boolean

False

quiet_error

If set, then exception stack information will not be added to the log

boolean

False

suppress_root_logging

If set, then no root handlers will be suppressed from logging.

boolean

False

uses

The YAML path represents a flow. It can be either a local file path or a URL.

string

None

reload

If set, auto-reloading on file changes is enabled: the Flow will restart while blocked if YAML configuration source is changed. This also applies apply to underlying Executors, if their source code or YAML configuration has changed.

boolean

False

env

The map of environment variables that are available inside runtime

object

None

inspect

The strategy on those inspect deployments in the flow.

If REMOVE is given then all inspect deployments are removed when building the flow.

string

COLLECT

Gateway arguments

These apply only to Flows, not Deployments

Name

Description

Type

Default

name

The name of this object.

This will be used in the following places:
- how you refer to this object in Python/YAML/CLI
- visualization
- log message header
- …

When not given, then the default naming strategy will apply.

string

gateway

workspace

The working directory for any IO operations in this object. If not set, then derive from its parent workspace.

string

None

log_config

The config name or the absolute path to the YAML config file of the logger used in this object.

string

default

quiet

If set, then no log will be emitted from this object.

boolean

False

quiet_error

If set, then exception stack information will not be added to the log

boolean

False

timeout_ctrl

The timeout in milliseconds of the control request, -1 for waiting forever

number

60

entrypoint

The entrypoint command overrides the ENTRYPOINT in Docker image. when not set then the Docker image ENTRYPOINT takes effective.

string

None

docker_kwargs

Dictionary of kwargs arguments that will be passed to Docker SDK when starting the docker ‘
container.

More details can be found in the Docker SDK docs: https://docker-py.readthedocs.io/en/stable/

object

None

prefetch

Number of requests fetched from the client before feeding into the first Executor.

Used to control the speed of data input into a Flow. 0 disables prefetch (1000 requests is the default)

number

1000

title

The title of this HTTP server. It will be used in automatics docs such as Swagger UI.

string

None

description

The description of this HTTP server. It will be used in automatics docs such as Swagger UI.

string

None

cors

If set, a CORS middleware is added to FastAPI frontend to allow cross-origin access.

boolean

False

no_debug_endpoints

If set, /status /post endpoints are removed from HTTP interface.

boolean

False

no_crud_endpoints

If set, /index, /search, /update, /delete endpoints are removed from HTTP interface.

Any executor that has @requests(on=...) bound with those values will receive data requests.

boolean

False

expose_endpoints

A JSON string that represents a map from executor endpoints (@requests(on=...)) to HTTP endpoints.

string

None

uvicorn_kwargs

Dictionary of kwargs arguments that will be passed to Uvicorn server when starting the server

More details can be found in Uvicorn docs: https://www.uvicorn.org/settings/

object

None

ssl_certfile

the path to the certificate file

string

None

ssl_keyfile

the path to the key file

string

None

expose_graphql_endpoint

If set, /graphql endpoint is added to HTTP interface.

boolean

False

protocol

Communication protocol of the server exposed by the Gateway. This can be a single value or a list of protocols, depending on your chosen Gateway. Choose the convenient protocols from: [‘GRPC’, ‘HTTP’, ‘WEBSOCKET’].

array

[<GatewayProtocolType.GRPC: 0>]

host

The host address of the runtime, by default it is 0.0.0.0.

string

0.0.0.0

proxy

If set, respect the http_proxy and https_proxy environment variables. otherwise, it will unset these proxy variables before start. gRPC seems to prefer no proxy

boolean

False

uses

The config of the gateway, it could be one of the followings:
* the string literal of an Gateway class name
* a Gateway YAML file (.yml, .yaml, .jaml)
* a docker image (must start with docker://)
* the string literal of a YAML config (must start with ! or jtype: )
* the string literal of a JSON config

When use it under Python, one can use the following values additionally:
- a Python dict that represents the config
- a text file stream has .read() interface

string

None

uses_with

Dictionary of keyword arguments that will override the with configuration in uses

object

None

py_modules

The customized python modules need to be imported before loading the gateway

Note that the recommended way is to only import a single module - a simple python file, if your
gateway can be defined in a single file, or an __init__.py file if you have multiple files,
which should be structured as a python package.

array

None

replicas

The number of replicas of the Gateway. This replicas will only be applied when converted into Kubernetes YAML

number

1

grpc_server_options

Dictionary of kwargs arguments that will be passed to the grpc server as options when starting the server, example : {‘grpc.max_send_message_length’: -1}

object

None

graph_description

Routing graph for the gateway

string

{}

graph_conditions

Dictionary stating which filtering conditions each Executor in the graph requires to receive Documents.

string

{}

deployments_addresses

JSON dictionary with the input addresses of each Deployment

string

{}

deployments_metadata

JSON dictionary with the request metadata for each Deployment

string

{}

deployments_no_reduce

list JSON disabling the built-in merging mechanism for each Deployment listed

string

[]

compression

The compression mechanism used when sending requests from the Head to the WorkerRuntimes. For more details, check https://grpc.github.io/grpc/python/grpc.html#compression.

string

None

timeout_send

The timeout in milliseconds used when sending data requests to Executors, -1 means no timeout, disabled by default

number

None

runtime_cls

The runtime class to run inside the Pod

string

GatewayRuntime

timeout_ready

The timeout in milliseconds of a Pod waits for the runtime to be ready, -1 for waiting forever

number

600000

env

The map of environment variables that are available inside runtime

object

None

env_from_secret

The map of environment variables that are read from kubernetes cluster secrets

object

None

floating

If set, the current Pod/Deployment can not be further chained, and the next .add() will chain after the last Pod/Deployment not this current one.

boolean

False

reload

If set, the Gateway will restart while serving if YAML configuration source is changed.

boolean

False

port

The port for input data to bind the gateway server to, by default, random ports between range [49152, 65535] will be assigned. The port argument can be either 1 single value in case only 1 protocol is used or multiple values when many protocols are used.

number

random in [49152, 65535]

monitoring

If set, spawn an http server with a prometheus endpoint to expose metrics

boolean

False

port_monitoring

The port on which the prometheus server is exposed, default is a random port between [49152, 65535]

number

random in [49152, 65535]

retries

Number of retries per gRPC call. If <0 it defaults to max(3, num_replicas)

number

-1

tracing

If set, the sdk implementation of the OpenTelemetry tracer will be available and will be enabled for automatic tracing of requests and customer span creation. Otherwise a no-op implementation will be provided.

boolean

False

traces_exporter_host

If tracing is enabled, this hostname will be used to configure the trace exporter agent.

string

None

traces_exporter_port

If tracing is enabled, this port will be used to configure the trace exporter agent.

number

None

metrics

If set, the sdk implementation of the OpenTelemetry metrics will be available for default monitoring and custom measurements. Otherwise a no-op implementation will be provided.

boolean

False

metrics_exporter_host

If tracing is enabled, this hostname will be used to configure the metrics exporter agent.

string

None

metrics_exporter_port

If tracing is enabled, this port will be used to configure the metrics exporter agent.

number

None

stateful

If set, start consensus module to make sure write operations are properly replicated between all the replicas

boolean

False

pod_ports

When using StatefulExecutors, if they want to restart it is important to keep the RAFT cluster configuration

number

None

executors#

Collection of Executors used in the Orchestration. In the case of a Deployment, this is a single Executor, while a Flow can have an arbitrary amount.

Each item in the collection specifies one Executor and can be used via:

dep = Deployment(uses=MyExec, arg1="foo", arg2="bar")
f = Flow().add(uses=MyExec, arg1="foo", arg2="bar")

Variables#

Jina Orchestration YAML supports variables and variable substitution according to the GitHub Actions syntax.

Environment variables#

Use ${{ ENV.VAR }} to refer to the environment variable VAR. You can find all Jina environment variables here.

Context variables#

Use ${{ CONTEXT.VAR }} to refer to the context variable VAR. Context variables can be passed in the form of a Python dictionary:

dep = Deployment.load_config('deployment.yml', context={...})
f = Flow.load_config('flow.yml', context={...})

Relative paths#

Use ${{root.path.to.var}} to refer to the variable var within the same YAML file, found at the provided path in the file’s structure.

Syntax: Environment variable vs relative path

The only difference between environment variable syntax and relative path syntax is the omission of spaces in the latter.