Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions docs/getting-started/concepts/feature-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Feature views consist of:
* (optional) `owner`: the email of the primary maintainer
* (optional) `org`: the organizational unit that owns the feature view (e.g. `"ads"`, `"search"`); useful for grouping feature views by team or product area
* (optional) a TTL, which limits how far back Feast will look when generating historical datasets. During online retrieval, values older than the TTL are still returned, but their field status is `OUTSIDE_MAX_AGE` instead of `PRESENT`
* (optional) `online_config`, which declares online retention and write semantics
* (optional) `enable_validation=True`, which enables schema validation during materialization (see [Schema Validation](#schema-validation) below)

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.
Expand Down Expand Up @@ -59,6 +60,33 @@ Feature views are used during
* 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).
* 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.

## Online retention configuration

`OnlineConfig` declares whether a feature view uses the current latest-value model or a sequence of historical values per entity. Sequence mode requires append writes. A maximum length and a maximum age are optional retention limits; leave both unset to keep an unlimited sequence.

```python
from datetime import timedelta

from feast import FeatureView, OnlineConfig

user_interactions = FeatureView(
name="user_interactions",
entities=[user],
schema=[...],
source=interactions_source,
online_config=OnlineConfig(
mode="sequence",
max_length=50,
max_age=timedelta(days=90),
write_mode="append",
),
)
```

{% hint style="warning" %}
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.
{% endhint %}

## Feature views without entities

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).
Expand Down
36 changes: 35 additions & 1 deletion protos/feast/core/FeatureView.proto
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,38 @@ message FeatureView {
FeatureViewMeta meta = 2;
}

// Next available id: 20
// Configuration for how feature values are retained in an online store.
// This message is currently a declarative contract; online store implementations
// opt into sequence behavior separately.
message OnlineConfig {
enum Mode {
// Preserve the current behavior: one latest value per entity.
LATEST = 0;

// Retain an ordered sequence of values per entity.
SEQUENCE = 1;
}

Mode mode = 1;

// Maximum number of events retained per entity. 0 means no length limit.
int32 max_length = 2;

// Maximum event age in whole seconds. 0 means no age limit.
int64 max_age_seconds = 3;

enum WriteMode {
// Preserve the current upsert behavior.
OVERWRITE = 0;

// Append a new event without overwriting earlier events.
APPEND = 1;
}

WriteMode write_mode = 4;
}

// Next available id: 22
// TODO(adchia): refactor common fields from this and ODFV into separate metadata proto
message FeatureViewSpec {
// Name of the feature view. Must be unique. Not updated.
Expand Down Expand Up @@ -125,6 +156,9 @@ message FeatureViewSpec {
// When true, the feature view will not serve online features or be materialized.
// Defaults to false (enabled) for backward compatibility.
bool disabled = 20;

// Online retention and write semantics for this feature view.
OnlineConfig online_config = 21;
}

message FeatureViewMeta {
Expand Down
2 changes: 2 additions & 0 deletions sdk/python/feast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from .filter_models import FilterTranslator
from .labeling import ConflictPolicy, LabelView
from .on_demand_feature_view import OnDemandFeatureView
from .online_config import OnlineConfig
from .project import Project
from .repo_config import RepoConfig
from .stream_feature_view import StreamFeatureView
Expand Down Expand Up @@ -69,6 +70,7 @@
"LabelView",
"ConflictPolicy",
"OnDemandFeatureView",
"OnlineConfig",
"RepoConfig",
"StreamFeatureView",
"ValueType",
Expand Down
7 changes: 7 additions & 0 deletions sdk/python/feast/batch_feature_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from feast.entity import Entity
from feast.feature_view import FeatureView
from feast.field import Field
from feast.online_config import OnlineConfig
from feast.protos.feast.core.DataSource_pb2 import DataSource as DataSourceProto
from feast.transformation.base import Transformation
from feast.transformation.mode import TransformationMode
Expand Down Expand Up @@ -45,6 +46,7 @@ class BatchFeatureView(FeatureView):
columns. If not specified, can be inferred from the underlying data source.
source: The batch source of data where this group of features is stored.
online: A boolean indicating whether online retrieval and write to online store is enabled for this feature view.
online_config: Optional online retention and write semantics.
offline: A boolean indicating whether offline retrieval and write to offline store is enabled for this feature view.
description: A human-readable description.
tags: A dictionary of key-value pairs to store arbitrary metadata.
Expand Down Expand Up @@ -92,6 +94,7 @@ def __init__(
ttl: Optional[timedelta] = None,
tags: Optional[Dict[str, str]] = None,
online: bool = False,
online_config: Optional[OnlineConfig] = None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Batch view copies lose online configuration

Copying a configured batch view drops online_config because BatchFeatureView.__copy__ omits it. Registry.apply_feature_view uses that copy for version pinning and unpromoted snapshots. Pinning raises a false conflict, while unpromoted versions silently lose their configuration.

Learn more

The new constructor argument is not preserved by BatchFeatureView.copy. That method reconstructs the batch view without online_config, resetting it to None. Registry.apply_feature_view compares the copy against the active view during version pinning, so an otherwise matching configured view fails the comparison. The same method copies unpromoted versions before serializing their snapshots, permanently omitting the configuration. SqlRegistry.apply_feature_view also uses the copy for pin comparisons.

Example: Register a batch view with sequence mode, max_length=50, and append writes. Add a feature and apply with no_promote=True. The new version snapshot contains no online configuration, although the submitted definition does.

Recommended fix: Pass online_config=self.online_config in BatchFeatureView.__copy__. Add regression tests for copied batch views, pinning a configured batch view, and preserving configuration in unpromoted version snapshots.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

offline: bool = False,
description: str = "",
owner: str = "",
Expand Down Expand Up @@ -151,6 +154,7 @@ def __init__(
ttl=ttl,
tags=tags,
online=online,
online_config=online_config,
offline=offline,
description=description,
owner=owner,
Expand Down Expand Up @@ -186,6 +190,7 @@ def __copy__(self) -> "BatchFeatureView":
aggregations=self.aggregations,
enable_validation=self.enable_validation,
version=self.version,
online_config=self.online_config,
)
fv.enabled = self.enabled
fv.state = self.state
Expand Down Expand Up @@ -277,6 +282,7 @@ def batch_feature_view(
source: Optional[DataSource] = None,
tags: Optional[Dict[str, str]] = None,
online: bool = True,
online_config: Optional[OnlineConfig] = None,
offline: bool = True,
description: str = "",
owner: str = "",
Expand Down Expand Up @@ -308,6 +314,7 @@ def decorator(user_function):
source=source,
tags=tags,
online=online,
online_config=online_config,
offline=offline,
description=description,
owner=owner,
Expand Down
12 changes: 12 additions & 0 deletions sdk/python/feast/cli/feature_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ def feature_view_describe(ctx: click.Context, name: str):
data["enabled"] = feature_view.enabled
if hasattr(feature_view, "state"):
data["state"] = feature_view.state.name
if feature_view.online_config is not None:
online_config = feature_view.online_config
data["spec"]["onlineConfig"] = {
"mode": online_config.mode,
"maxLength": online_config.max_length,
"maxAgeSeconds": (
int(online_config.max_age.total_seconds())
if online_config.max_age is not None
else None
),
"writeMode": online_config.write_mode,
}
print(yaml.dump(data, default_flow_style=False, sort_keys=False))


Expand Down
18 changes: 17 additions & 1 deletion sdk/python/feast/diff/registry_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ def tag_objects_for_keep_delete_update_add(

FIELDS_TO_IGNORE = {"project"}

# Message fields where "unset" and "set with all default values" mean different
# things. Protobuf compares both as equal by value, so check presence too.
PRESENCE_AWARE_FIELDS = {"online_config"}


def _presence_changed(
current_spec: FeastObjectSpecProto, new_spec: FeastObjectSpecProto, field: str
) -> bool:
if field not in PRESENCE_AWARE_FIELDS:
return False
return cast(Any, current_spec).HasField(field) != cast(Any, new_spec).HasField(
field
)


def diff_registry_objects(
current: FeastObject, new: FeastObject, object_type: FeastObjectType
Expand All @@ -147,7 +161,9 @@ def diff_registry_objects(
for _field in current_spec.DESCRIPTOR.fields:
if _field.name in FIELDS_TO_IGNORE:
continue
elif getattr(current_spec, _field.name) != getattr(new_spec, _field.name):
elif getattr(current_spec, _field.name) != getattr(
new_spec, _field.name
) or _presence_changed(current_spec, new_spec, _field.name):
if _field.name == "feature_transformation":
current_spec = cast(OnDemandFeatureViewSpec, current_spec)
new_spec = cast(OnDemandFeatureViewSpec, new_spec)
Expand Down
27 changes: 26 additions & 1 deletion sdk/python/feast/feature_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from feast.entity import Entity
from feast.feature_view_projection import FeatureViewProjection
from feast.field import Field
from feast.online_config import OnlineConfig
from feast.proto_utils import (
mode_to_string,
serialize_data_source,
Expand Down Expand Up @@ -129,6 +130,8 @@ class FeatureView(BaseFeatureView):
can be inferred from the underlying data source.
online: A boolean indicating whether online retrieval is enabled for this feature
view.
online_config: Optional online retention and write semantics. Sequence mode is
declarative until implemented by an online store.
description: A human-readable description.
tags: A dictionary of key-value pairs to store arbitrary metadata.
owner: The owner of the feature view, typically the email of the primary
Expand All @@ -149,6 +152,7 @@ class FeatureView(BaseFeatureView):
entity_columns: List[Field]
features: List[Field]
online: bool
online_config: Optional[OnlineConfig]
offline: bool
description: str
tags: Dict[str, str]
Expand All @@ -171,6 +175,7 @@ def __init__(
entities: Optional[List[Entity]] = None,
ttl: Optional[timedelta] = timedelta(days=0),
online: bool = True,
online_config: Optional[OnlineConfig] = None,
offline: bool = False,
description: str = "",
tags: Optional[Dict[str, str]] = None,
Expand Down Expand Up @@ -198,6 +203,8 @@ def __init__(
can result in extremely computationally intensive queries.
online (optional): A boolean indicating whether online retrieval is enabled for
this feature view.
online_config (optional): Online retention and write semantics for this feature
view. Defaults to the current latest-value behavior when omitted.
offline (optional): A boolean indicating whether write to offline store is enabled for
this feature view.
description (optional): A human-readable description.
Expand All @@ -223,6 +230,7 @@ def __init__(
self.enable_validation = enable_validation
self.entities = [e.name for e in entities] if entities else [DUMMY_ENTITY_NAME]
self.ttl = ttl
self.online_config = online_config
schema = schema or []
self.mode = mode

Expand Down Expand Up @@ -353,6 +361,7 @@ def __copy__(self):
schema=self.schema,
tags=self.tags,
online=self.online,
online_config=self.online_config,
offline=self.offline,
sink_source=self.batch_source if self.source_views else None,
enable_validation=self.enable_validation,
Expand Down Expand Up @@ -389,7 +398,7 @@ def _schema_or_udf_changed(self, other: "BaseFeatureView") -> bool:

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

Expand All @@ -404,6 +413,7 @@ def __eq__(self, other):
sorted(self.entities) != sorted(other.entities)
or self.ttl != other.ttl
or self.online != other.online
or self.online_config != other.online_config
or self.offline != other.offline
or self.batch_source != other.batch_source
or self.stream_source != other.stream_source
Expand Down Expand Up @@ -437,6 +447,9 @@ def ensure_valid(self):
"""
super().ensure_valid()

if self.online_config is not None:
self.online_config.validate()

if not self.entities:
raise ValueError("Feature view has no entities.")

Expand Down Expand Up @@ -549,6 +562,11 @@ def to_proto_spec(
org=self.org,
ttl=(ttl_duration if ttl_duration is not None else None),
online=self.online,
online_config=(
self.online_config.to_proto()
if self.online_config is not None
else None
),
Comment on lines +565 to +569

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Default online configuration changes are ignored

With local SQLite, feast apply ignores changes between online_config=None and OnlineConfig() when nothing else changes. diff_registry_objects compares child messages without checking presence, so it reports UNCHANGED. The registry retains the previous configuration instead of storing or clearing it.

Learn more

An omitted message and a present message containing only default-valued fields differ in protobuf presence, but their child messages compare equal. OnlineConfig() serializes entirely to default values, making this distinction reachable for the new field. diff_registry_objects compares field values without HasField, so it produces no property differences for either direction. The CLI's planned apply flow, used for the local provider with SQLite, skips unchanged objects in apply_diff_to_registry. Direct SDK apply does not use this diff filter, so the existing apply test does not cover the failure.

Example: Register a view with online_config=OnlineConfig(), remove that argument, and run feast apply using the local provider and SQLite. With no other changes, the plan reports no update and the registry still contains the explicit configuration.

Recommended fix: Make registry diffing presence-aware for message fields, including online_config. Test both adding and clearing OnlineConfig() through the plan/apply-diffs flow while keeping all other fields unchanged.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

offline=self.offline,
batch_source=batch_source_proto,
stream_source=stream_source_proto,
Expand Down Expand Up @@ -633,6 +651,11 @@ def _from_proto_internal(
)
for view_spec in feature_view_proto.spec.source_views
]
online_config = (
OnlineConfig.from_proto(feature_view_proto.spec.online_config)
if feature_view_proto.spec.HasField("online_config")
else None
)

from feast.batch_feature_view import BatchFeatureView

Expand Down Expand Up @@ -685,6 +708,7 @@ def _from_proto_internal(
owner=feature_view_proto.spec.owner,
org=feature_view_proto.spec.org,
online=feature_view_proto.spec.online,
online_config=online_config,
offline=feature_view_proto.spec.offline,
ttl=(
timedelta(days=0)
Expand Down Expand Up @@ -714,6 +738,7 @@ def _from_proto_internal(
owner=feature_view_proto.spec.owner,
org=feature_view_proto.spec.org,
online=feature_view_proto.spec.online,
online_config=online_config,
offline=feature_view_proto.spec.offline,
ttl=(
timedelta(days=0)
Expand Down
9 changes: 9 additions & 0 deletions sdk/python/feast/infra/registry/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,15 @@ def _update_metadata_fields(
existing_proto.spec.enable_validation = getattr(
updated_fv, "enable_validation"
)
if hasattr(existing_proto.spec, "online_config") and isinstance(
updated_fv, FeatureView
):
if updated_fv.online_config is None:
existing_proto.spec.ClearField("online_config")
else:
existing_proto.spec.online_config.CopyFrom(
updated_fv.online_config.to_proto()
)

# Enabled/disabled state
if hasattr(existing_proto.spec, "disabled") and hasattr(updated_fv, "enabled"):
Expand Down
Loading
Loading