Online Feature Serving

Connect to the Feature Store

import hsfs

connection = hsfs.connection()
fs = connection.get_feature_store()
Starting Spark application
IDYARN Application IDKindStateSpark UIDriver log
4application_1619309085643_0005pysparkidleLinkLink
SparkSession available as 'spark'.
Connected. Call `.close()` to terminate connection gracefully.

Get training dataset

td_meta = fs.get_training_dataset("card_fraud_model", 1)

To identify which primary key names are used for this training dataset query use serving_keys method

#`init_prepared_statement` method is needed to get serving_keys in case `get_serving_vector` has not beed called yet. This is not necessary for `get_serving_vector` method itself
td_meta.init_prepared_statement() 
td_meta.serving_keys
{'cc_num'}

For demo purposes lets prepare list of primary key values that we are interested in to buils feature vectore from online feature store

card_numbers = ["4867010117638802",
                 "4564139086560436", 
                 "4638396144844325",
                 "4460285888258185", 
                 "4032763187099525", 
                 "4650661577010550", 
                ]
for card_number in card_numbers:
    serving_vector = td_meta.get_serving_vector({'cc_num': card_number})
    print (serving_vector)
[0.0, 53.98, 1, 2, 386.655, 438.35670686097643, 8, 3033.6029145826396, 1224.9825]
[0.0, 64.4, 1, 2, 365.545, 398.1364731470856, 11, 31.47860260269159, 49.25272727272728]
[0.0, 74.43, 1, 1, 46.2, 0.0, 8, 205.78118536445453, 136.8475]
[0.0, 38.16, 1, 2, 11.29, 15.273506473629428, 8, 3685.9662745141004, 2106.3062499999996]
[0.0, 36.26, 1, 1, 68.58, 0.0, 10, 1204.4018071612704, 425.006]
[0.0, 86.05, 1, 1, 55.5, 0.0, 10, 1645.126762256737, 755.586]