jina.drivers¶
-
jina.drivers.
store_init_kwargs
(func)[source]¶ Mark the args and kwargs of
__init__()
later to be stored viasave_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, gettop_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 fieldarg1
andarg2
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
, useself._arg1 =
, note the underscore in the front.To access
arg1
, simply useself.arg1
. It automatically switch between default_arg1
andarg1
from the request.
For successful value reading, the following condition must be met:
the
name
in the proto must match with the current class namethe
disabled
field in the proto should not beFalse
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.
-
class
jina.drivers.
BaseDriver
(priority=0, *args, **kwargs)[source]¶ Bases:
jina.jaml.JAMLCompatible
A
BaseDriver
is a logic unit above thejina.peapods.runtimes.zmq.zed.ZEDRuntime
. It reads the protobuf message, extracts/modifies the required information and then return the message back tojina.peapods.runtimes.zmq.zed.ZEDRuntime
.A
BaseDriver
needs to beattached
to ajina.peapods.runtimes.zmq.zed.ZEDRuntime
before using. This is done byattach()
. Note that a deserializedBaseDriver
from file is always unattached.- Parameters
priority (
int
) – the priority of its default arg values (hardcoded in Python). If the receivedQueryLang
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 saveargs
(in a list) andkwargs
(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
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
queryset
¶ - Return type
-
property
logger
¶ Shortcut to
self.runtime.logger
- Return type
-
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
¶
-
property
-
class
jina.drivers.
FastRecursiveMixin
[source]¶ Bases:
object
The optimized version of
RecursiveMixin
, to be mixed in withBaseRecursiveDriver
it usestraverse()
inDocumentSet
and yield much better performance for index and encode drivers.-
property
docs
¶ The DocumentSet after applying the traversal
- Return type
-
property
-
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 eitherFastRecursiveMixin
orRecursiveMixin
Initialize a
BaseRecursiveDriver
- Parameters
-
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 thejina.peapods.runtimes.zmq.zed.ZEDRuntime
andjina.executors.BaseExecutor
It reads the protobuf message, extracts/modifies the required information and then sends to thejina.executors.BaseExecutor
, finally it returns the message back tojina.peapods.runtimes.zmq.zed.ZEDRuntime
.A
BaseExecutableDriver
needs to beattached
to ajina.peapods.runtimes.zmq.zed.ZEDRuntime
andjina.executors.BaseExecutor
before using. This is done byattach()
. Note that a deserializedBaseDriver
from file is always unattached.Initialize a
BaseExecutableDriver
- Parameters
executor (
Optional
[str
]) – the name of the sub-executor, only necessary whenjina.executors.compound.CompoundExecutor
is usedmethod (
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
-
runtime
: Optional[ZEDRuntime]¶