Sub topic 8
The feature repository and feast apply
This chapter assumes you can read Python and YAML and use a shell. It also assumes you know what entities, data sources and feature views are from the earlier chapters. Here you will see how those definitions are laid out in a feature repository. You will also see how feast apply turns them into registered state.
What a feature repository is
A feature repository is a directory that holds two kinds of files:
- One
feature_store.yamlfile. It configures the project: where the registry lives and which offline and online stores to use. - One or more Python files. They define entities, data sources, feature views and feature services as ordinary Python objects.
You manage this directory like application code, in version control. The definitions are declarative. Importing the file creates objects but moves no data and writes nothing to any store. Nothing in your running system changes until you register the definitions.
A typical layout looks like this:
driver_project/
feature_store.yaml
features.py
data/
driver_stats.parquetFeast finds the Python files by scanning the repository directory for definitions. You can split definitions across several files. A file named in .feastignore is skipped, and the syntax matches .gitignore. Use it for test scripts and notebooks that would otherwise be imported during apply.
feature_store.yaml
This file tells Feast how to build a FeatureStore object. A minimal local configuration looks like this:
project: driver_project
registry: data/registry.db
provider: local
online_store:
type: sqlite
path: data/online_store.db
offline_store:
type: file| Key | Meaning |
|---|---|
| `project` | A namespace. Objects with the same name in different projects do not collide. |
| `registry` | Where registry metadata is stored. A relative path is resolved against the repository directory. |
| `provider` | The environment family, such as `local`, `gcp` or `aws`. It sets defaults for the other components. |
| `online_store` | The key-value store that serves the latest values. |
| `offline_store` | The engine that reads historical data to build training sets. |
Two points cause most confusion. First, the project name is part of every registered object's identity. If you rename it and run feast apply, you create a second project, not a rename. Second, the .db suffix on the registry file is only a naming convention. With a file registry, Feast stores serialized protobuf messages there, not SQL tables.
Defining objects in the repository
The Python file declares everything the project exposes:
from datetime import timedelta
from feast import Entity, FeatureService, 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,
)
driver_activity_v1 = FeatureService(
name="driver_activity_v1",
features=[driver_stats_fv[["conv_rate", "acc_rate"]]],
)Every object is a module-level variable. Feast discovers definitions by inspecting module attributes, so an object created inside a function and never assigned at module level is not registered. Names must be unique within a project for each object type.
The path in FileSource is relative. Run Feast from the repository directory, or pass repo_path explicitly. Otherwise the source file is not found.
What feast apply does
Run the command from the repository directory:
feast applyIf you run it elsewhere, use feast -c path/to/repo apply.
feast apply performs these steps:
- It reads
feature_store.yamland builds the store configuration. - It imports the Python files and collects the objects it finds.
- It compares those objects with what the registry already holds for the project.
- It writes new and changed objects to the registry, and removes registered objects that are no longer in the code.
- It updates infrastructure. For the online store, it creates tables or other structures for new online-enabled feature views and removes them for deleted ones.
The comparison in step 3 makes the command idempotent. Running it twice with no code changes alters nothing. It also makes the repository the source of truth: the registry follows your code, not the other way around.
What the registry stores
The registry holds metadata only. It records:
- Entities with their join keys.
- Data source definitions, including paths and timestamp column names.
- Feature views, with schema, TTL, and the online flag.
- Feature services and the feature references they contain.
- Timestamps of the most recent materialization for each feature view.
It does not hold feature values. Values stay in your offline source and, after materialization, in the online store. The registry is what lets get_historical_features and get_online_features resolve a reference like driver_hourly_stats:conv_rate to a source, an entity key and a TTL.
You can inspect it from Python:
from feast import FeatureStore
store = FeatureStore(repo_path=".")
for entity in store.list_entities():
print("entity:", entity.name)
for fv in store.list_feature_views():
print("feature view:", fv.name, [f.name for f in fv.features])
for fs in store.list_feature_services():
print("feature service:", fs.name)From the shell, feast entities list, feast feature-views list and feast feature-services list show the same information.
Apply is not materialize
After feast apply the online store has structure but no data. Loading values is a separate step:
feast apply
feast materialize-incremental $(date -u +"%Y-%m-%dT%H:%M:%S")Calling get_online_features between the two commands returns None values for the features. Beginners often read this as a bug in the definitions. It means only that nothing has been materialized yet. apply changes metadata and infrastructure. materialize copies data.
Because materialize-incremental uses the last-materialized timestamps kept in the registry, the registry is also the thing that stops a scheduled job from reloading old data.
Editing definitions safely
Because apply follows the code, small edits have large effects:
- Changing a schema. Adding a field to a feature view is generally safe. Changing a field's type or the entity can make old online values unreadable, so re-materialize afterward.
- Renaming a feature view. Feast sees a deletion and a creation. The old online table is dropped, and the new one starts empty until you materialize.
- Removing a definition. Deleting an object from the code removes it from the registry on the next
apply. Any feature service that still references it will fail to register. - Removing everything.
feast teardowndeletes the registered infrastructure for the project. Never run it against a shared environment you do not own.
Common errors
| Symptom | Likely cause |
|---|---|
| `feature_store.yaml` not found | You ran the command outside the repository and did not pass `-c`. |
| Source file not found | The source `path` is relative and resolved from the wrong directory. |
| A feature view is missing after apply | It is not a module-level variable, or its file matches `.feastignore`. |
| `apply` removes objects you wanted | The checkout lacked their definitions. |
| Online features come back as `None` | Nothing is materialized yet, or the data is older than the TTL. |
| Feature service fails to register | It references a feature view or feature name that does not exist. |
A good habit is to run apply in a throwaway project first, such as a different project value with a local registry. You can then check the object lists before pointing the same code at a shared registry.
Exercise
You rename the feature view driver_hourly_stats to driver_stats_hourly in your repository and run feast apply. A service then calls get_online_features with the new name and gets only None values. Why, and what do you do?
Show answer
Feast treats the rename as a deletion of the old feature view and a creation of a new one. The old online table is dropped, and the new table is created empty, because apply registers metadata and does not copy data. Run feast materialize-incremental (or feast materialize with an explicit start and end time) so the new feature view is populated. Also update any feature services and callers that still use the old name.
Exercise
What does the registry store, and what does it not store?
Show answer
It stores metadata: entities, data sources, feature views, feature services, their schemas and TTLs, and materialization timestamps. It does not store feature values. Those stay in the offline source and, after materialization, in the online store.