Skip to content

Commit fdeee98

Browse files
committed
feat: Add online sequence configuration foundation
Signed-off-by: Chaitany Patel <patelchaitany93@gmail.com>
1 parent d4e9619 commit fdeee98

14 files changed

Lines changed: 553 additions & 18 deletions

File tree

‎docs/getting-started/concepts/feature-view.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Feature views consist of:
2626
* (optional) `owner`: the email of the primary maintainer
2727
* (optional) `org`: the organizational unit that owns the feature view (e.g. `"ads"`, `"search"`); useful for grouping feature views by team or product area
2828
* (optional) a TTL, which limits how far back Feast will look when generating historical datasets
29+
* (optional) `online_config`, which declares online retention and write semantics
2930
* (optional) `enable_validation=True`, which enables schema validation during materialization (see [Schema Validation](#schema-validation) below)
3031

3132
Feature views allow Feast to model your existing feature data in a consistent way in both an offline (training) and online (serving) environment. Feature views generally contain features that are properties of a specific object, in which case that object is defined as an entity and included in the feature view.
@@ -59,6 +60,33 @@ Feature views are used during
5960
* Loading of feature values into an online store. Feature views determine the storage schema in the online store. Feature values can be loaded from batch sources or from [stream sources](../../reference/data-sources/push.md).
6061
* Retrieval of features from the online store. Feature views provide the schema definition to Feast in order to look up features from the online store.
6162

63+
## Online retention configuration
64+
65+
`OnlineConfig` declares whether a feature view uses the current latest-value model or a bounded sequence of historical values per entity. Sequence mode requires append writes and a positive maximum length. An optional maximum age adds a second retention limit.
66+
67+
```python
68+
from datetime import timedelta
69+
70+
from feast import FeatureView, OnlineConfig
71+
72+
user_interactions = FeatureView(
73+
name="user_interactions",
74+
entities=[user],
75+
schema=[...],
76+
source=interactions_source,
77+
online_config=OnlineConfig(
78+
mode="sequence",
79+
max_length=50,
80+
max_age=timedelta(days=90),
81+
write_mode="append",
82+
),
83+
)
84+
```
85+
86+
{% hint style="warning" %}
87+
Sequence configuration is currently an experimental registry contract. Online stores continue to use their existing latest-value behavior until they explicitly implement sequence append, retrieval, and eviction support.
88+
{% endhint %}
89+
6290
## Feature views without entities
6391

6492
If a feature view contains features that are not related to a specific entity, the feature view can be defined without entities (only timestamps are needed for this feature view).

‎protos/feast/core/FeatureView.proto‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,38 @@ message FeatureView {
5656
FeatureViewMeta meta = 2;
5757
}
5858

59-
// Next available id: 20
59+
// Configuration for how feature values are retained in an online store.
60+
// This message is currently a declarative contract; online store implementations
61+
// opt into sequence behavior separately.
62+
message OnlineConfig {
63+
enum Mode {
64+
// Preserve the current behavior: one latest value per entity.
65+
LATEST = 0;
66+
67+
// Retain an ordered sequence of values per entity.
68+
SEQUENCE = 1;
69+
}
70+
71+
Mode mode = 1;
72+
73+
// Maximum number of events retained per entity. 0 means unset.
74+
int32 max_length = 2;
75+
76+
// Maximum event age in whole seconds. 0 means unset.
77+
int64 max_age_seconds = 3;
78+
79+
enum WriteMode {
80+
// Preserve the current upsert behavior.
81+
OVERWRITE = 0;
82+
83+
// Append a new event without overwriting earlier events.
84+
APPEND = 1;
85+
}
86+
87+
WriteMode write_mode = 4;
88+
}
89+
90+
// Next available id: 22
6091
// TODO(adchia): refactor common fields from this and ODFV into separate metadata proto
6192
message FeatureViewSpec {
6293
// Name of the feature view. Must be unique. Not updated.
@@ -125,6 +156,9 @@ message FeatureViewSpec {
125156
// When true, the feature view will not serve online features or be materialized.
126157
// Defaults to false (enabled) for backward compatibility.
127158
bool disabled = 20;
159+
160+
// Online retention and write semantics for this feature view.
161+
OnlineConfig online_config = 21;
128162
}
129163

130164
message FeatureViewMeta {

‎sdk/python/feast/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from .filter_models import FilterTranslator
3737
from .labeling import ConflictPolicy, LabelView
3838
from .on_demand_feature_view import OnDemandFeatureView
39+
from .online_config import OnlineConfig
3940
from .project import Project
4041
from .repo_config import RepoConfig
4142
from .stream_feature_view import StreamFeatureView
@@ -66,6 +67,7 @@
6667
"LabelView",
6768
"ConflictPolicy",
6869
"OnDemandFeatureView",
70+
"OnlineConfig",
6971
"RepoConfig",
7072
"StreamFeatureView",
7173
"ValueType",

‎sdk/python/feast/batch_feature_view.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from feast.entity import Entity
1212
from feast.feature_view import FeatureView
1313
from feast.field import Field
14+
from feast.online_config import OnlineConfig
1415
from feast.protos.feast.core.DataSource_pb2 import DataSource as DataSourceProto
1516
from feast.transformation.base import Transformation
1617
from feast.transformation.mode import TransformationMode
@@ -43,6 +44,7 @@ class BatchFeatureView(FeatureView):
4344
columns. If not specified, can be inferred from the underlying data source.
4445
source: The batch source of data where this group of features is stored.
4546
online: A boolean indicating whether online retrieval and write to online store is enabled for this feature view.
47+
online_config: Optional online retention and write semantics.
4648
offline: A boolean indicating whether offline retrieval and write to offline store is enabled for this feature view.
4749
description: A human-readable description.
4850
tags: A dictionary of key-value pairs to store arbitrary metadata.
@@ -90,6 +92,7 @@ def __init__(
9092
ttl: Optional[timedelta] = None,
9193
tags: Optional[Dict[str, str]] = None,
9294
online: bool = False,
95+
online_config: Optional[OnlineConfig] = None,
9396
offline: bool = False,
9497
description: str = "",
9598
owner: str = "",
@@ -149,6 +152,7 @@ def __init__(
149152
ttl=ttl,
150153
tags=tags,
151154
online=online,
155+
online_config=online_config,
152156
offline=offline,
153157
description=description,
154158
owner=owner,
@@ -189,6 +193,7 @@ def batch_feature_view(
189193
source: Optional[DataSource] = None,
190194
tags: Optional[Dict[str, str]] = None,
191195
online: bool = True,
196+
online_config: Optional[OnlineConfig] = None,
192197
offline: bool = True,
193198
description: str = "",
194199
owner: str = "",
@@ -220,6 +225,7 @@ def decorator(user_function):
220225
source=source,
221226
tags=tags,
222227
online=online,
228+
online_config=online_config,
223229
offline=offline,
224230
description=description,
225231
owner=owner,

‎sdk/python/feast/cli/feature_views.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ def feature_view_describe(ctx: click.Context, name: str):
4444
data["enabled"] = feature_view.enabled
4545
if hasattr(feature_view, "state"):
4646
data["state"] = feature_view.state.name
47+
if feature_view.online_config is not None:
48+
online_config = feature_view.online_config
49+
data["spec"]["onlineConfig"] = {
50+
"mode": online_config.mode,
51+
"maxLength": online_config.max_length,
52+
"maxAgeSeconds": (
53+
int(online_config.max_age.total_seconds())
54+
if online_config.max_age is not None
55+
else None
56+
),
57+
"writeMode": online_config.write_mode,
58+
}
4759
print(yaml.dump(data, default_flow_style=False, sort_keys=False))
4860

4961

‎sdk/python/feast/feature_view.py‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from feast.entity import Entity
2828
from feast.feature_view_projection import FeatureViewProjection
2929
from feast.field import Field
30+
from feast.online_config import OnlineConfig
3031
from feast.proto_utils import (
3132
mode_to_string,
3233
serialize_data_source,
@@ -129,6 +130,8 @@ class FeatureView(BaseFeatureView):
129130
can be inferred from the underlying data source.
130131
online: A boolean indicating whether online retrieval is enabled for this feature
131132
view.
133+
online_config: Optional online retention and write semantics. Sequence mode is
134+
declarative until implemented by an online store.
132135
description: A human-readable description.
133136
tags: A dictionary of key-value pairs to store arbitrary metadata.
134137
owner: The owner of the feature view, typically the email of the primary
@@ -149,6 +152,7 @@ class FeatureView(BaseFeatureView):
149152
entity_columns: List[Field]
150153
features: List[Field]
151154
online: bool
155+
online_config: Optional[OnlineConfig]
152156
offline: bool
153157
description: str
154158
tags: Dict[str, str]
@@ -171,6 +175,7 @@ def __init__(
171175
entities: Optional[List[Entity]] = None,
172176
ttl: Optional[timedelta] = timedelta(days=0),
173177
online: bool = True,
178+
online_config: Optional[OnlineConfig] = None,
174179
offline: bool = False,
175180
description: str = "",
176181
tags: Optional[Dict[str, str]] = None,
@@ -198,6 +203,8 @@ def __init__(
198203
can result in extremely computationally intensive queries.
199204
online (optional): A boolean indicating whether online retrieval is enabled for
200205
this feature view.
206+
online_config (optional): Online retention and write semantics for this feature
207+
view. Defaults to the current latest-value behavior when omitted.
201208
offline (optional): A boolean indicating whether write to offline store is enabled for
202209
this feature view.
203210
description (optional): A human-readable description.
@@ -223,6 +230,7 @@ def __init__(
223230
self.enable_validation = enable_validation
224231
self.entities = [e.name for e in entities] if entities else [DUMMY_ENTITY_NAME]
225232
self.ttl = ttl
233+
self.online_config = online_config
226234
schema = schema or []
227235
self.mode = mode
228236

@@ -353,6 +361,7 @@ def __copy__(self):
353361
schema=self.schema,
354362
tags=self.tags,
355363
online=self.online,
364+
online_config=self.online_config,
356365
offline=self.offline,
357366
sink_source=self.batch_source if self.source_views else None,
358367
enable_validation=self.enable_validation,
@@ -389,7 +398,7 @@ def _schema_or_udf_changed(self, other: "BaseFeatureView") -> bool:
389398

390399
# Skip UDF-related data source fields: batch_source, stream_source
391400
# (treat as deployment configuration, not schema changes)
392-
# Skip configuration: ttl, online, offline, enable_validation
401+
# Skip configuration: ttl, online, online_config, offline, enable_validation
393402
# Skip metadata: materialization_intervals (excluded in current equality)
394403
return False
395404

@@ -404,6 +413,7 @@ def __eq__(self, other):
404413
sorted(self.entities) != sorted(other.entities)
405414
or self.ttl != other.ttl
406415
or self.online != other.online
416+
or self.online_config != other.online_config
407417
or self.offline != other.offline
408418
or self.batch_source != other.batch_source
409419
or self.stream_source != other.stream_source
@@ -437,6 +447,9 @@ def ensure_valid(self):
437447
"""
438448
super().ensure_valid()
439449

450+
if self.online_config is not None:
451+
self.online_config.validate()
452+
440453
if not self.entities:
441454
raise ValueError("Feature view has no entities.")
442455

@@ -549,6 +562,11 @@ def to_proto_spec(
549562
org=self.org,
550563
ttl=(ttl_duration if ttl_duration is not None else None),
551564
online=self.online,
565+
online_config=(
566+
self.online_config.to_proto()
567+
if self.online_config is not None
568+
else None
569+
),
552570
offline=self.offline,
553571
batch_source=batch_source_proto,
554572
stream_source=stream_source_proto,
@@ -633,6 +651,11 @@ def _from_proto_internal(
633651
)
634652
for view_spec in feature_view_proto.spec.source_views
635653
]
654+
online_config = (
655+
OnlineConfig.from_proto(feature_view_proto.spec.online_config)
656+
if feature_view_proto.spec.HasField("online_config")
657+
else None
658+
)
636659

637660
has_transformation = feature_view_proto.spec.HasField("feature_transformation")
638661

@@ -682,6 +705,7 @@ def _from_proto_internal(
682705
owner=feature_view_proto.spec.owner,
683706
org=feature_view_proto.spec.org,
684707
online=feature_view_proto.spec.online,
708+
online_config=online_config,
685709
offline=feature_view_proto.spec.offline,
686710
ttl=(
687711
timedelta(days=0)
@@ -711,6 +735,7 @@ def _from_proto_internal(
711735
owner=feature_view_proto.spec.owner,
712736
org=feature_view_proto.spec.org,
713737
online=feature_view_proto.spec.online,
738+
online_config=online_config,
714739
offline=feature_view_proto.spec.offline,
715740
ttl=(
716741
timedelta(days=0)

‎sdk/python/feast/infra/registry/registry.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,15 @@ def _update_metadata_fields(
609609
existing_proto.spec.enable_validation = getattr(
610610
updated_fv, "enable_validation"
611611
)
612+
if hasattr(existing_proto.spec, "online_config") and isinstance(
613+
updated_fv, FeatureView
614+
):
615+
if updated_fv.online_config is None:
616+
existing_proto.spec.ClearField("online_config")
617+
else:
618+
existing_proto.spec.online_config.CopyFrom(
619+
updated_fv.online_config.to_proto()
620+
)
612621

613622
# Enabled/disabled state
614623
if hasattr(existing_proto.spec, "disabled") and hasattr(updated_fv, "enabled"):

0 commit comments

Comments
 (0)