📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Data Engineering MLOps and Feature Stores

MLOps and Feature Stores

5 min read
Feature stores decouple feature computation from model training and serving — Feast enables offline and online access.

MLOps and Feature Stores

# Feature Store: centralised repository of ML features
# Offline: for training (historical)
# Online:  for serving (real-time, low latency)

# Feast (open source feature store)
from feast import FeatureStore, FeatureView, Field, Entity
from feast.types import Float64, Int64

store = FeatureStore(repo_path="feature_repo/")

# Define entity
customer = Entity(name="customer_id", value_type=Int64)

# Define feature view
customer_stats_view = FeatureView(
    name="customer_stats",
    entities=[customer],
    schema=[
        Field(name="total_orders",  dtype=Int64),
        Field(name="avg_order_value", dtype=Float64),
        Field(name="days_since_last_order", dtype=Int64)
    ],
    source=BigQuerySource(table="myproject.myds.customer_stats")
)

# Training: get historical features
training_df = store.get_historical_features(
    entity_df=entity_df,  # customer_id + event_timestamp
    features=["customer_stats:total_orders","customer_stats:avg_order_value"]
).to_df()

# Serving: get real-time features
feature_vector = store.get_online_features(
    features=["customer_stats:total_orders"],
    entity_rows=[{"customer_id": 42}]
).to_dict()