Sub topic 8
The Feature Repository and `feast apply`
This chapter assumes you know Python basics, pandas DataFrames, machine-learning features and labels, and the difference between batch data and real-time serving.
A Feast feature repository is a project directory that describes how features are defined, stored, and retrieved. It usually contains:
feature_store.yaml, which configures the registry and stores.- Python files, which define entities, data sources, feature views, and feature services.
- Data files or connections to external data systems.
feast apply reads these definitions and registers their metadata. It does not copy every feature value into the online store.
Configure the repository
A minimal feature_store.yaml can use local files for development:
project: driver_project
registry: data/registry.db
provider: local
online_store:
type: sqlite
path: data/online_store.db
offline_store:
type: fileThe project name identifies the Feast project. The registry path identifies the metadata database. The registry records definitions such as feature view names, schemas, entities, and versions.
The online store holds the latest values used for low-latency inference. SQLite is convenient for local tests. The offline store holds historical data used to build training sets. A file-based offline store is useful for a small local example.
Paths in this file are normally relative to the feature repository directory. Run Feast commands from that directory so that Feast finds the configuration and definition files.
Define feature metadata
A Python definition file describes the objects that Feast should register:
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,
)An entity identifies the thing described by a feature, such as a driver. Its join_keys tell Feast which column connects entity rows to feature rows.
A data source tells Feast where feature data comes from and which column contains event time. The event timestamp is essential for historical retrieval.
A feature view groups related features that share an entity, source, and general freshness policy. Its schema gives each feature a name and data type. The ttl says how long a feature value remains valid for retrieval. The online=True setting makes the view eligible for online serving.
Run `feast apply`
From the repository directory, run:
feast applyFeast loads the Python definitions, validates their configuration, and updates the registry. The registry then becomes the shared catalog that other Feast commands use.
feast apply does not materialize values into the online store. Materialization is a separate operation. This separation lets you change metadata and deploy data independently.
Common errors
- Running
feast applyfrom the wrong directory, so Feast cannot findfeature_store.yaml. - Using a join-key name that differs between the entity definition and the source data.
- Omitting or misnaming the event timestamp column.
- Declaring a schema type that does not match the source data.
- Expecting
feast applyto make new values immediately available online.
Exercise
After changing a feature view's schema, which command registers the changed definition, and which separate operation populates current values in the online store?
Show answer
Run feast apply to update the registry. Then run materialization, such as feast materialize-incremental <timestamp>, to copy eligible historical values into the online store.