Sub topic 13
Grouping Features for a Model with Feature Services
Prerequisites
This chapter assumes that you know Python, pandas DataFrames, and the basic machine learning workflow. You should also understand entities, feature views, and the difference between historical retrieval for training and online retrieval for inference.
A feature service is a named group of features that a model is allowed to use. It creates a stable interface between a model and the feature store. Instead of listing feature names throughout training and serving code, both paths refer to the same feature service definition.
Why use a feature service?
A feature view can contain more features than one model needs. For example, a driver feature view might contain conversion rate, acceptance rate, and average daily trips. One model might use only the first two.
A feature service selects the required features:
- It documents the inputs for a model.
- It prevents accidental use of unrelated features.
- It keeps training and serving code aligned.
- It allows several models to use different projections of the same feature view.
- It gives a model input contract that can be versioned.
The feature service does not copy feature data. It references features already defined in feature views.
| Object | Purpose |
|---|---|
| Feature view | Defines related features, their schema, source, and freshness |
| Feature service | Selects the features required by one model |
| Historical retrieval | Uses the service to build training data |
| Online retrieval | Uses the service to fetch inference inputs |
Define a feature service
The following definition selects two features from the driver_hourly_stats feature view. The feature view is assumed to have been defined in the same Feast repository.
from feast import FeatureService
driver_activity_v1 = FeatureService(
name="driver_activity_v1",
features=[
driver_stats_fv[["conv_rate", "acc_rate"]],
],
)The expression driver_stats_fv[["conv_rate", "acc_rate"]] creates a projection of the feature view. The projection contains only the named fields. The service name, driver_activity_v1, is the identifier that training and serving code use.
The suffix v1 is a useful convention. If a model later needs a different input set, create another service such as driver_activity_v2. Changing the existing service can make an old model receive unexpected inputs.
A service can combine projections from multiple feature views. Every selected feature must still have a compatible entity relationship with the entity rows used for retrieval.
Use the service for training and serving
Use the service name when requesting historical features for training. Feast resolves the service to its selected feature references and performs the appropriate point-in-time join.
training_df = store.get_historical_features(
entity_df=entity_df,
features=["driver_activity_v1"],
).to_df()For online inference, use the same service name:
online_features = store.get_online_features(
features=["driver_activity_v1"],
entity_rows=[{"driver_id": 1001}],
).to_dict()Using the same service in both paths reduces training-serving skew. The model sees the same logical feature set during training and inference, although the storage systems and retrieval methods differ.
After adding or changing the service, run feast apply so Feast registers the definition. The registry records the service name and its feature references. It does not replace the source data or materialize values by itself.
Common errors
- Defining a service but continuing to hard-code separate feature lists in application code.
- Renaming or changing a service used by a deployed model without testing compatibility.
- Selecting a feature that is not present in the referenced feature view.
- Assuming that
feast applyloads feature values into the online store. Materialization is a separate operation. - Using different feature services for training and serving without checking whether the difference is intentional.
Exercise
A model was trained with convrate and accrate. You want a new version that also uses avgdailytrips. Should you edit driveractivityv1 or create another service?
Show answer
Create another service, such as driveractivityv2. Keeping v1 unchanged preserves the input contract expected by the existing model.