Sub topic 3
Materializing features into the online store
Prerequisites: You have a Feast repository with an entity, a FileSource, and a feature view, and you have run feast apply once. You can use pandas DataFrames and know the difference between training data and inference requests.
Materializing features into the online store
Materialization copies the latest feature values from the offline source into the online store, which serves low-latency reads. Each run processes only the data since the previous run:
feast materialize-incremental $(date -u +"%Y-%m-%dT%H:%M:%S")Serving features with get_online_features
Online reads look up rows by entity key, not by time. The result is the most recently materialized value:
from feast import FeatureStore
store = FeatureStore(repo_path=".")
features = store.get_online_features(
features=["driver_hourly_stats:conv_rate", "driver_hourly_stats:acc_rate"],
entity_rows=[{"driver_id": 1001}],
).to_dict()The keys in entity_rows must match the entity's join keys.
Grouping features for a model with feature services
A FeatureService is a named list of features. Training and serving then request the same list. Add this to the feature repository, reusing the driver_stats_fv feature view:
from feast import FeatureService
driver_activity_v1 = FeatureService(
name="driver_activity_v1",
features=[driver_stats_fv[["conv_rate", "acc_rate"]]],
)Pass the service to a read with store.get_feature_service("driver_activity_v1").
TTL, staleness and keeping training and serving consistent
A time to live (TTL) is how long a feature value stays valid after its event timestamp. The feature view above sets ttl=timedelta(days=1). Older values are returned as missing. Training-serving skew usually comes from computing the same feature in two different code paths. Define each feature once in the repository and read it from both places.
Request-time transformations with on-demand feature views
An on-demand feature view computes a value when a request arrives, from stored features plus request inputs. Use it for values that depend on the request, such as a ratio. It runs on every request, so keep the computation small.
Pushing fresh feature values from streams and events
A push source lets an application write feature values straight into the online store. This makes events visible in seconds, without waiting for a materialization run. Assume a PushSource named driver_stats_push_source exists in the repository:
import pandas as pd
from feast import FeatureStore
from feast.data_source import PushMode
store = FeatureStore(repo_path=".")
now = pd.Timestamp.now(tz="UTC")
df = pd.DataFrame({
"driver_id": [1001],
"conv_rate": [0.8],
"acc_rate": [0.95],
"avg_daily_trips": [12],
"event_timestamp": [now],
"created": [now],
})
store.push("driver_stats_push_source", df, to=PushMode.ONLINE)Moving to production: store choices, scheduling and the feature server
Local defaults suit development. Production deployments usually change the stores:
| Layer | Local default | Typical production choice |
|---|---|---|
| Registry | Local file | Shared SQL or object store registry |
| Offline store | Parquet files | Data warehouse such as BigQuery, Snowflake or Redshift |
| Online store | SQLite | Redis or DynamoDB |
Schedule feast materialize-incremental with cron or an orchestrator. Run feast serve to expose features over HTTP.
Exercise
Exercise
A feature value was materialized yesterday, and its TTL is one day. What does getonlinefeatures return for it today?
Show answer
The value is past its TTL relative to its event timestamp, so Feast returns it as missing (null) rather than as a stale value.