Skip to content

Extensions and Speed Up

Vectorized keys

To speed up calculations, faas provides users with the concept of feature vectorization. Some parameters for some features can be written as a list of elements, where each element must be a valid parameter. In this case, instead of one feature, N features will be calculated, formed from the Cartesian product of the requested list of features. In the simplest case, this is a list of one element.

Vectorization allows you to calculate many features at the cost of calculating only one feature.

Simple example:

circle_feature = {
    'type': 'circle',
    'dataset': 'ru-pub-households/apartments',
    'field': ['apartments', 'price', 'rooms'],
    'limit': 300,
    'agg': ['sum', 'mean'],
    'fillna': 0,
}

As you can see, 2 fields are vectorized here: 'field': ['apartments', 'price', 'rooms'] and 'agg': ['sum', 'mean']. Thus, the result will be calculated 6 features as a Cartesian product of lists.

The following fields support vectorization: 'field', 'agg' for each type of feature, except Match_aggregate.

Since each feature must have a unique name, a template is used as the name of vectorized features. Example:

config = {
    ...,
    'features': {
        'apartments_{{FIELD}}_{{AGG}}': {
            'type': 'circle',
            'dataset': 'ru-pub-households/apartments',
            'field': ['price', 'year'],
            'limit': 300,
            'agg': ['mean', 'max'],
            'fillna': 0,
        }
    }
}

Based on the apartments_{{FIELD}}_{{AGG}} template, 4 features will be created:

  • apartments_price_mean,
  • apartments_year_mean,
  • apartments_price_max,
  • apartments_year_max.