Integration With Model Serving

Integrating features in model schema definition

To integrate a Qwak model with a batch feature set, specify the features in the model's schema function:

import qwak
from qwak.model.schema import (
    ModelSchema,
    Prediction
)
from qwak.model.schema_entities import FeatureStoreInput


def schema(self):
    model_schema = ModelSchema(
        features=[FeatureStoreInput("user-features.user_id"),
                 FeatureStoreInput("user-feature.registration_country")],
        predictions=[
            Prediction(name="score", type=float)
        ])
    return model_schema


@qwak.features_extraction
def predict(self, df, extracted_df):
    return self.model.predict(extracted_df)

Each batch feature set feature must be named using its name as a prefix, followed by the . and the feature name. For example, if the feature set has the name: user-feature, and the feature itself is called user_id, the full name of the feature is user-features.user_id.

πŸ’‘

Fetching all features of a feature set

You can use * to integrate all of the features Instead of explicitly defining each one

import qwak
from qwak.model.schema import (
    ModelSchema,
    Prediction
)
from qwak.model.schema_entities import FeatureStoreInput


def schema(self):
    model_schema = ModelSchema(
        features=[FeatureStoreInput("batch-feature-set-name.*")],
        predictions=[
            Prediction(name="score", type=float)
        ])
    return model_schema


@qwak.features_extraction
def predict(self, df, extracted_df):
    return self.model.predict(extracted_df)

The features_extraction decorator will fetch the up-to-date feature value from the online store and inject them into the extracted_df.