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

Parameters

func (Callable) – the Callable to wrap

Return type

Callable

Returns

the wrapped 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

Warning

For the sake of cooperative multiple inheritance, do NOT implement __init__() for this class

property as_querylang

Render as QueryLang parameters.

class jina.drivers.DriverType(*args, **kwargs)[source]

Bases: jina.jaml.JAMLCompatibleType, type

A meta class representing a Driver

When a new Driver is created, it gets registered

Create and register a new class with this meta class.

Parameters
  • *args

    *args for super

  • **kwargs

    **kwargs for super

Returns

the newly registered class

static register_class(cls)[source]

Register a class

Parameters

cls – the class

Returns

the class, after being registered

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

Bases: jina.jaml.JAMLCompatible

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

A BaseDriver needs to be attached to a jina.peapods.runtimes.zmq.zed.ZEDRuntime 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

  • *args

    not used (kept to maintain interface)

  • **kwargs

    not used (kept to maintain interface)

store_args_kwargs = False

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

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

Attach this driver to a jina.peapods.runtimes.zmq.zed.ZEDRuntime

Parameters
  • runtime (ZEDRuntime) – the pea to be attached

  • *args

    not used (kept to maintain interface)

  • **kwargs

    not used (kept to maintain interface)

Return type

None

property req

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

Return type

Request

property partial_reqs

The collected partial requests under the current request_id

Return type

Sequence[ForwardRef]

property expect_parts

The expected number of partial messages

Return type

int

property msg

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

Return type

Message

property queryset
Return type

QueryLangSet

property logger

Shortcut to self.runtime.logger

Return type

JinaLogger

class jina.drivers.RecursiveMixin[source]

Bases: object

A mixin to traverse a set of Documents with a specific path. to be mixed in with BaseRecursiveDriver

property docs
class jina.drivers.FastRecursiveMixin[source]

Bases: object

The optimized version of RecursiveMixin, to be mixed in with BaseRecursiveDriver it uses traverse() in DocumentSet and yield much better performance for index and encode drivers.

property docs

The DocumentSet after applying the traversal

Return type

DocumentSet

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

Bases: jina.drivers.BaseDriver

A BaseRecursiveDriver is an abstract Driver class containing information about the traversal_paths that a Driver must apply its logic. It is intended to be mixed in with either FastRecursiveMixin or RecursiveMixin

Initialize a BaseRecursiveDriver

Parameters
  • traversal_paths (Tuple[str]) – Describes the leaves of the document tree on which _apply_all are called

  • *args

    *args for super

  • **kwargs

    **kwargs for super

runtime: Optional[ZEDRuntime]
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.runtimes.zmq.zed.ZEDRuntime 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.runtimes.zmq.zed.ZEDRuntime.

A BaseExecutableDriver needs to be attached to a jina.peapods.runtimes.zmq.zed.ZEDRuntime 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

  • *args

    *args for super

  • **kwargs

    **kwargs for super

property exec

the executor that to which the instance is attached

Return type

AnyExecutor

property exec_fn

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

Return type

Callable

Returns

the Callable to execute in the driver

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

Attach the driver to a jina.executors.BaseExecutor

Parameters
  • executor (AnyExecutor) – the executor to which we attach

  • *args

    *args for super().attach()

  • **kwargs

    **kwargs for super().attach()

Return type

None

runtime: Optional[ZEDRuntime]