Define features and push velocity data
For the complete documentation index see: llms.txt
All documentation pages available in markdown.
On this page, you define a push-backed feature view, register it with feast apply, and push one velocity snapshot to confirm the write path. The Aerospike online store reference and Feast push source reference cover the full configuration options.
Create the feature repository
Create the project directory, feature store configuration, and the push-backed feature view definition.
-
Create a project directory:
Terminal window mkdir -p fraud-feast-demo/datacd fraud-feast-demo -
Create
feature_store.yaml:feature_store.yaml project: fraud_detectionregistry: data/registry.dbprovider: localonline_store:type: aerospikehosts:- ["127.0.0.1", 3000]namespace: testttl_seconds: 600read_timeout_ms: 150write_timeout_ms: 300entity_key_serialization_version: 3offline_store:type: fileregistry: data/registry.dbis Feast’s local metadata store for entity and feature view definitions.offline_store: type: fileis required by Feast even in push-only demos. Feast validates its presence but does not use it for reading in this tutorial.ttl_seconds: 600covers a five-minute velocity window plus buffer.provider: local,entity_key_serialization_version: 3, and thehostslist format are explained in Tutorial: Serve real-time Feast features with Aerospike on the Define and materialize page. -
Create
fraud_repo.py:fraud_repo.py from datetime import timedeltafrom feast import Entity, FeatureService, FeatureView, Field, FileSource, PushSourcefrom feast.types import Float64, Int64from feast.value_type import ValueTypeaccount = Entity(name="account",join_keys=["account_id"],value_type=ValueType.STRING,description="Bank or wallet account identifier",)txn_velocity_batch = FileSource(path="data/txn_velocity.parquet",timestamp_field="event_timestamp",)txn_velocity_push = PushSource(name="txn_velocity_push",batch_source=txn_velocity_batch,)txn_velocity_fv = FeatureView(name="txn_velocity_5m",entities=[account],ttl=timedelta(minutes=10),schema=[Field(name="txn_count_5m", dtype=Int64),Field(name="amount_sum_5m", dtype=Float64),Field(name="distinct_merchants_5m", dtype=Int64),],online=True,source=txn_velocity_push,tags={"domain": "fraud", "window": "5m"}, # Descriptive only. Feast routing does not use tags.)fraud_scoring_service = FeatureService(name="fraud_scoring_v1",features=[txn_velocity_fv],description="Velocity features for real-time fraud scoring",)PushSourceallowsbatch_sourceto be omitted, but this tutorial defines features throughFeatureView. Feast’sFeatureViewconstructor requires abatch_sourceon every stream source, includingPushSource, sotxn_velocity_batchis included here. ThatFileSourceregisters schema forfeast applyand is not used when you write throughstore.push()at runtime. The Parquet file it references does not need to exist at apply time.txn_velocity_pushis the source name you pass tostore.push().txn_velocity_5mis the feature view name Feast uses in the registry and feature references.online=Truemarks the feature view as eligible for online serving. It is the default value forFeatureView. Settingonline=Falserestricts the view to offline retrieval and preventsget_online_featuresfrom reading it.ttl=timedelta(minutes=10)controls Feast materialization lookback and historical point-in-time retrieval. It does not make the standard Aerospike online read reject an old value.ttl_seconds: 600infeature_store.yamlis the serving-layer control: Aerospike expires the record ten minutes after its latest write.FeatureServicewraps the feature view under a named service. Your request referencesfraud_scoring_v1rather than enumerating individual features. Coordinate service-membership changes with the model’s expected schema and version the service when its contract changes. -
Register definitions:
feast applyreads the Python definitions in your project directory and records them in the Feast registry atdata/registry.db. From that point, commands and SDK calls know your entity, feature view, and feature service by name. It registers definitions only. It does not move any feature values.Terminal window feast applyExpected result No project found in the repository. Using project name fraud_detection defined in feature_store.yamlApplying changes for project fraud_detectionDeploying infrastructure for txn_velocity_5m -
Confirm registration:
- Output includes
Applying changes for project fraud_detection. - Output includes
Deploying infrastructure for txn_velocity_5m.
- Output includes
Push a velocity snapshot
Write a velocity snapshot into the Aerospike online store with store.push() and read it back to confirm the write and read paths work end to end. The values you push here stand in for the output of a real aggregation job.
-
Create
push_velocity.py:push_velocity.py from datetime import datetime, timezoneimport pandas as pdfrom feast import FeatureStorefrom feast.data_source import PushModestore = FeatureStore(repo_path=".")snapshot = pd.DataFrame({"account_id": ["acct-1001"],"event_timestamp": [datetime.now(timezone.utc)],"txn_count_5m": [7],"amount_sum_5m": [1243.50],"distinct_merchants_5m": [3],})store.push("txn_velocity_push", snapshot, to=PushMode.ONLINE)print("Pushed velocity snapshot for acct-1001")FeatureStore(repo_path=".")loads the registry fromfeature_store.yamlin the current directory.store.push()takes a pandasDataFrame. It must include the entity join key (account_id),event_timestamp, and oneDataFramecolumn for every feature field defined intxn_velocity_5m, with column names matching theFieldnames exactly.event_timestamprecords when the velocity snapshot was computed, here set to the current system time. Production scoring code or monitoring can inspect that timestamp to enforce a stricter freshness limit than the record TTL.The first argument to
store.push()is thePushSourcename (txn_velocity_push), not the feature view name. Feast routes the pushed values to the right feature view through the source name.PushMode.ONLINEwrites only to the Aerospike online store.PushMode.ONLINE_AND_OFFLINEalso requires a writable batch source for offline history, as explained on the Wrap up page. -
Run it:
Terminal window python3 push_velocity.pyExpected result Pushed velocity snapshot for acct-1001 -
Confirm the push:
- The script prints
Pushed velocity snapshot for acct-1001without errors. PushMode.ONLINEwrote only to the Aerospike online store.
- The script prints
On the next page, you read features through the FeatureService and optional HTTP feature server.