Sub topic 7
Defining Feature Views
This chapter assumes you know Python, pandas DataFrames, basic machine learning terms, and the difference between batch data and real-time serving. You should also understand that an entity identifies the thing for which a feature is stored, such as a driver or customer.
A FeatureView is a named definition of related features. It tells Feast:
- Which entity keys identify each row.
- Where the feature data comes from.
- Which columns are features and what types they have.
- How long a value remains valid.
- Whether Feast should make the features available online.
A FeatureView is a declaration, not usually a table that Feast creates by itself. Feast uses the declaration when it builds historical training data or loads values into an online store.
Connect an entity to a data source
Suppose a delivery model predicts whether a driver will accept a trip. The driver is the entity. The source contains hourly driver statistics.
from datetime import timedelta
from feast import Entity, FeatureView, Field, FileSource
from feast.types import Float32, Int64
driver = Entity(
name="driver",
join_keys=["driver_id"],
)
driver_stats_source = FileSource(
name="driver_hourly_stats_source",
path="data/driver_stats.parquet",
timestamp_field="event_timestamp",
created_timestamp_column="created",
)
driver_stats_fv = FeatureView(
name="driver_hourly_stats",
entities=[driver],
ttl=timedelta(days=1),
schema=[
Field(name="conv_rate", dtype=Float32),
Field(name="acc_rate", dtype=Float32),
Field(name="avg_daily_trips", dtype=Int64),
],
online=True,
source=driver_stats_source,
)The join_keys value names the column Feast uses to match entity rows with feature rows. The source's timestamp_field records when a feature value was observed. Feast needs this timestamp for point-in-time-correct historical retrieval.
The schema lists the columns exposed by the FeatureView. A Float32 field stores a floating-point value, while Int64 stores an integer. Naming the fields explicitly prevents accidental exposure of unrelated source columns.
The ttl is the time-to-live. Here, a feature value older than one day is considered expired for the view. TTL does not update the source or guarantee that a new value exists. It defines how long Feast considers the value valid.
How a FeatureView is used
Set online=True when the view should be available after materialization for low-latency inference. A view used only for batch training can remain offline.
A FeatureView should group features that share an entity, source, timestamp semantics, and update behavior. Do not combine unrelated features merely because they are used by the same model. A FeatureService can group model-specific features later.
Exercise
Why does a FeatureView need both an entity definition and a source timestamp?
Show answer
The entity definition tells Feast which rows belong together, and the source timestamp lets Feast select the value that existed at the relevant event time.