Sub topic 4
Online Features: Latest Values at Low Latency
This chapter assumes you know Python, pandas DataFrames, basic machine learning terms, and the difference between batch data and real-time serving. You also need a Feast repository with an applied FeatureView and an online store.
What online features are
An online feature is a feature value retrieved during model inference. Inference is the step where a trained model receives input and produces a prediction.
For example, a driver-risk model might need the latest conv_rate and acc_rate for driver 1001. The model cannot wait for a large historical query to scan every trip. It needs a small response quickly.
Feast stores these latest values in an online store. An online store is a low-latency database optimized for lookup by entity key. The entity key identifies the object for which Feast stores features.
| Concern | Online feature access |
|---|---|
| Main use | Real-time model inference |
| Data returned | Latest materialized value for each entity |
| Lookup | Entity key, such as `driver_id` |
| Typical requirement | Low response latency |
| Common limitation | Usually not intended for large historical queries |
The online store does not automatically contain every value from the source. A separate materialization step copies selected recent values from the offline source into the online store.
Retrieving features with Feast
Suppose the repository defines a feature view named driver_hourly_stats. The following code requests two features for one driver:
from feast import FeatureStore
store = FeatureStore(repo_path=".")
online_features = store.get_online_features(
features=[
"driver_hourly_stats:conv_rate",
"driver_hourly_stats:acc_rate",
],
entity_rows=[
{"driver_id": 1001},
],
).to_dict()
print(online_features)FeatureStore loads the repository configuration. The features list uses the format feature_view:feature_name. The entity_rows list supplies the join key values. Feast uses driver_id to find the corresponding row in the online store.
The returned dictionary usually contains the entity key and the requested feature columns. Your application can convert these values into the input format expected by the model.
Materialization comes first
Before an online lookup can return a current value, the feature must be materialized. Materialization means copying feature values from an offline source into the online store.
feast materialize-incremental 2025-01-01T13:00:00This command materializes data up to the timestamp provided. In production, a scheduler commonly runs this command repeatedly. The schedule should match how often the source data changes and how fresh the model input must be.
Common errors
- Using the wrong entity key: The request key must match the entity's declared join key, such as
driver_id. - Requesting an unregistered feature: Run
feast applyafter changing repository definitions. - Expecting historical values: Use
get_historical_featuresfor training data. Online retrieval is for current serving values. - Ignoring missing values: An entity may not have been materialized yet, or its feature may have expired because of its time-to-live setting.
- Materializing too rarely: Slow materialization creates stale predictions even when the source data is fresh.
Exercise
A prediction request needs the latest conv_rate for driver 1001. Which Feast method should you use, and what must happen before the request?
Show answer
Use get_online_features with driver_id set to 1001. The feature definition must be applied, and a materialization job must have copied a recent value into the online store.