Sub topic 3
Offline Features: Large, Historical, Batch Access
This chapter assumes Python, pandas DataFrames, basic machine learning terms, and familiarity with batch data. You will use Feast’s offline store to build a historical training dataset.
What an offline feature store does
An offline feature store keeps feature values together with their historical timestamps. It is designed for large reads rather than individual, low-latency requests. Typical storage includes a data warehouse, data lake, or files such as Parquet.
A training job usually starts with an entity table. Each row identifies an entity, such as a driver, and the time when a prediction would have been made. Feast then retrieves feature values that were available at that time.
| Use case | Access pattern | Typical result |
|---|---|---|
| Training data | Large historical batch query | A DataFrame with many rows |
| Exploration | Filtered historical query | A sample of past feature values |
| Backtesting | Repeated time-based queries | Data from several past periods |
The offline store is different from a database used for real-time predictions. It can scan and join a large amount of history, but it does not need to return one entity’s features in a few milliseconds.
The historical retrieval workflow
A Feast feature source contains records with an event timestamp. The timestamp says when the feature value became valid. An entity DataFrame contains the entity keys and the prediction timestamps.
Feast’s get_historical_features method joins these inputs. For each entity row, it selects feature values from the same entity that existed at or before the row’s timestamp. This prevents the training set from using information from the future.
from datetime import datetime
import pandas as pd
from feast import FeatureStore
store = FeatureStore(repo_path=".")
entity_df = pd.DataFrame(
{
"driver_id": [1001, 1002],
"event_timestamp": [
datetime(2025, 1, 1, 12, 0),
datetime(2025, 1, 1, 13, 0),
],
}
)
training_df = store.get_historical_features(
entity_df=entity_df,
features=[
"driver_hourly_stats:conv_rate",
"driver_hourly_stats:acc_rate",
"driver_hourly_stats:avg_daily_trips",
],
).to_df()
print(training_df)The feature references use the form feature_view:feature_name. The returned DataFrame contains the original entity columns and the requested feature columns. It may also contain timestamps or metadata columns supplied by the source.
Batch access and data volume
Offline retrieval is useful when the training set contains millions of rows. The storage engine can perform distributed scans and joins instead of loading the complete source into Python memory at once. The exact execution model depends on the offline store, such as a warehouse or file-based store.
A training query should request only the features needed by the model. Unnecessary columns increase scan cost and make data validation harder.
Where offline features fit
Offline features are also useful for evaluation and backtesting. They let you reproduce what the model could have known at earlier times instead of accidentally using today’s values.
Exercise
Why should an entity DataFrame include an event_timestamp column when retrieving historical features?
Show answer
Feast uses each timestamp to select feature values that were available at that time. Without it, the result cannot reliably represent the information available when each prediction would have been made.