jina.drivers

jina.drivers.store_init_kwargs(func)[source]

Mark the args and kwargs of __init__() later to be stored via save_config() in YAML

Return type

Callable

class jina.drivers.QuerySetReader[source]

Bases: object

QuerySetReader allows a driver to read arguments from the protobuf message. This allows a driver to override its behavior based on the message it receives. Extremely useful in production, for example, get top_k results, doing pagination, filtering.

To register the field you want to read from the message, simply register them in __init__(). For example, __init__(self, arg1, arg2, **kwargs) will allow the driver to read field arg1 and arg2 from the message. When they are not found in the message, the value _arg1 and _arg2 will be used. Note the underscore prefix.

Note

  • To set default value of arg1, use self._arg1 =, note the underscore in the front.

  • To access arg1, simply use self.arg1. It automatically switch between default _arg1 and arg1 from the request.

For successful value reading, the following condition must be met:

  • the name in the proto must match with the current class name

  • the disabled field in the proto should not be False

  • the priority in the proto should be strictly greater than the driver’s priority (by default is 0)

  • the field name must exist in proto’s parameters

class jina.drivers.DriverType[source]

Bases: type

static register_class(cls)[source]
class jina.drivers.BaseDriver(priority=0, *args, **kwargs)[source]

Bases: object

A BaseDriver is a logic unit above the jina.peapods.pea.BasePea. It reads the protobuf message, extracts/modifies the required information and then return the message back to jina.peapods.pea.BasePea.

A BaseDriver needs to be attached to a jina.peapods.pea.BasePea before using. This is done by attach(). Note that a deserialized BaseDriver from file is always unattached.

Parameters

priority (int) – the priority of its default arg values (hardcoded in Python). If the received QueryLang has a higher priority, it will override the hardcoded value

store_args_kwargs = False

set this to True to save args (in a list) and kwargs (in a map) in YAML config

attached = None

represent if this driver is attached to a jina.peapods.pea.BasePea (& jina.executors.BaseExecutor)

attach(pea, *args, **kwargs)[source]

Attach this driver to a jina.peapods.pea.BasePea

Parameters

pea (BasePea) – the pea to be attached.

Return type

None

property req

Get the current (typed) request, shortcut to self.pea.request

Return type

Request

property msg

Get the current request, shortcut to self.pea.message

Return type

Message

property queryset
Return type

Iterator[QueryLang]

property envelope

Get the current request, shortcut to self.pea.message

Return type

Envelope

property logger

Shortcut to self.pea.logger

Return type

JinaLogger

classmethod to_yaml(representer, data)[source]

Required by ruamel.yaml.constructor

classmethod from_yaml(constructor, node)[source]

Required by ruamel.yaml.constructor

class jina.drivers.BaseRecursiveDriver(traversal_paths=('c', 'r'), *args, **kwargs)[source]

Bases: jina.drivers.BaseDriver

Parameters

traversal_paths (Tuple[str]) – The describes the leaves of the document tree on which _apply_all are called

class jina.drivers.BaseExecutableDriver(executor=None, method=None, *args, **kwargs)[source]

Bases: jina.drivers.BaseRecursiveDriver

A BaseExecutableDriver is an intermediate logic unit between the jina.peapods.pea.BasePea and jina.executors.BaseExecutor It reads the protobuf message, extracts/modifies the required information and then sends to the jina.executors.BaseExecutor, finally it returns the message back to jina.peapods.pea.BasePea.

A BaseExecutableDriver needs to be attached to a jina.peapods.pea.BasePea and jina.executors.BaseExecutor before using. This is done by attach(). Note that a deserialized BaseDriver from file is always unattached.

Initialize a BaseExecutableDriver

Parameters
  • executor (Optional[str]) – the name of the sub-executor, only necessary when jina.executors.compound.CompoundExecutor is used

  • method (Optional[str]) – the function name of the executor that the driver feeds to

property exec

the executor that attached

Return type

AnyExecutor

property exec_fn

the function of jina.executors.BaseExecutor() to call

Return type

Callable

attach(executor, *args, **kwargs)[source]

Attach the driver to a jina.executors.BaseExecutor

Return type

None