Getting Features for Inference

This tutorial shows how to access data stored in the Qwak Feature Store online store during the inference.

Using OnlineClient

In the predict function, we create an instance of the OnlineClient.

After that, we create a ModelSchema containing all of the features we want to retrieve.

We create a DataFrame containing the entities identifiers and pass it to the Feature Store. As a response, we get a Pandas DataFrame with the requested features.

import pandas as pd
from qwak.feature_store.online.client import OnlineClient
from qwak.model.schema_entities import FeatureStoreInput, Entity
from qwak.model.schema import ModelSchema

entity = Entity(name='user')

model_schema = ModelSchema(
    inputs=[
        FeatureStoreInput(name='user-credit-risk-features.checking_account',  entity=entity),
        FeatureStoreInput(name='user-credit-risk-features.age',  entity=entity),
        FeatureStoreInput(name='user-credit-risk-features.job',  entity=entity),
        FeatureStoreInput(name='user-credit-risk-features.duration',  entity=entity),
        FeatureStoreInput(name='user-credit-risk-features.credit_amount',  entity=entity),
        FeatureStoreInput(name='user-credit-risk-features.housing',  entity=entity),
        FeatureStoreInput(name='user-credit-risk-features.purpose',  entity=entity),
        FeatureStoreInput(name='user-credit-risk-features.saving_account',  entity=entity),
        FeatureStoreInput(name='user-credit-risk-features.sex',  entity=entity),
        FeatureStoreInput(name='liked-posts.count',  entity=entity)
    ])
    
online_client = OnlineClient()

df = pd.DataFrame(columns=[               'user',               		 'post_id'],
                  data   =[['06cc255a-aa07-4ec9-ac69-b896ccf05322',   '1234'],
                           ['asdc255a-aa07-4ec9-ac69-b896c1231445',   '7889']])
                  
user_features = online_client.get_feature_values(model_schema, df)

print(user_features)