Compute Functions
Functions are defined by -
- Wrapping a Python function with a decorator
@indexify_function
- Defining the runnable compute logic as a class if you have to initialize expensive values.
Defining a Function with Decorators
Attributes:
name
(optional): Name of the function. If not provided, the function name is used.description
(optional): Description of the function. If not provided, the doc string of a function is used as a description.image
(optional): Name of the image in which the function should run. If not provided, it’s assumed the default image calledtensorlake/indexify-executor-default
is used.accumulate
(optional): Initial value for the accumulator. If not provided, the function is not an reducer. You can define any Pydantic object with default values.payload_encoder
(optional): Serialization method to store the outputs of the function. If not provided,cloudpickle
is used. Possible values:cloudpickle
,json
.
Defining a Function as Class
Sometimes you want to initialize some expensive objects before running the function. In such cases, you can define the function as a class.
The same attributes that are available for the decorator can be set as attributes of the class.
Dynamic Routers
Dynamic Routers enable routing data from an upstream function to one or more downstream functions by applying custom logic.
They are equivalent to if-else conditions in a programming language.
In this example even_odd_router
function routes the input to print_even
if the input is even, otherwise to print_odd
.
They are added to the graphs as any other function and can be used to define complex workflows.
The print_even
and print_odd
functions are added as downstream functions to the even_odd_router
function
Was this page helpful?