Skip to content
Open
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
3 changes: 2 additions & 1 deletion docs/user_guides/fs/feature_group/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ This section serves to provide guides and examples for the common usage of abstr
- [Data Types and Schema management](data_types.md)
- [Statistics](statistics.md)
- [Data Validation](data_validation.md)
- [Feature Monitoring](feature_monitoring.md)
- [Feature Monitoring](feature_monitoring.md)
- [Time-To-Live (TTL)](ttl.md)
92 changes: 92 additions & 0 deletions docs/user_guides/fs/feature_group/ttl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
## Feature Group TTL Usage Guide

Below are examples showing how to work with TTL (Time To Live) on feature groups.

---

### 1. Create a Feature Group with TTL Enabled

```python
from datetime import datetime, timezone
import pandas as pd

# Assume you already have a feature store handle
# fs = ...

now = datetime.now(timezone.utc)
df = pd.DataFrame(
{
"id": [0, 1, 2],
"timestamp": [now, now, now],
"feature1": [10, 20, 30],
"feature2": ["a", "b", "c"],
}
)

fg = fs.create_feature_group(
name="fg_ttl_example",
version=1,
primary_key=["id"],
event_time="timestamp",
online_enabled=True,
ttl=60, # TTL in seconds
)

fg.insert(
df,
write_options={
"start_offline_materialization": False,
"wait_for_online_ingestion": True,
},
)

fg.read(online=True) # return empty df after ttl
```

---

### 2. Update the TTL Value

```python
# Example: change TTL to a new value (in seconds)
new_ttl_seconds = 120
# Later, update TTL
fg.enable_ttl(new_ttl_seconds)

---

### 3. Disable TTL and Enable It Again

```python
# Disable TTL
fg.disable_ttl()

# ... time passes, you decide to enforce TTL again ...

# Re‑enable TTL with a new value (in seconds)
fg.enable_ttl() # If ttl is not set, the feature group will be enabled with the last TTL value being set.

# Or Re‑enable TTL with a new value (in seconds)
fg.enable_ttl(ttl=90)
```

---

### 4. Enable TTL on an Existing Feature Group (Created Without TTL)

```python
# Assume this FG was created earlier without TTL
fg = fs.get_feature_group(
name="fg_existing_no_ttl",
version=1,
)

# Enable TTL for the first time
fg.enable_ttl(ttl=60) # seconds

```


### Reference

API reference on all possible types of ttl value can be found [here.](https://docs.hopsworks.ai/hopsworks-api/latest/generated/api/feature_group_api/#enable_ttl)
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ nav:
- Notification: user_guides/fs/feature_group/notification.md
- On-Demand Transformations: user_guides/fs/feature_group/on_demand_transformations.md
- Online Ingestion Observability: user_guides/fs/feature_group/online_ingestion_observability.md
- Time-To-Live (TTL): user_guides/fs/feature_group/ttl.md
- Feature View:
- user_guides/fs/feature_view/index.md
- Overview: user_guides/fs/feature_view/overview.md
Expand Down