""" User feature views for recommendation system. """ from datetime import timedelta from feast import FeatureView, Field from feast.infra.offline_stores.snowflake_source import SnowflakeSource from feast.types import Float32, Int64, String, UnixTimestamp from .entities import user, creator from .config import get_snowflake_database, get_snowflake_schema # Snowflake data source for user creator features user_creator_features_source = SnowflakeSource( name="user_creator_features_snowflake", database=get_snowflake_database(), schema=get_snowflake_schema(), table="RECS_HOOKS_RANKER_USER_CREATOR_FEATURE_STORE", timestamp_field="EVENT_TIMESTAMP", created_timestamp_column="CREATED_TIMESTAMP", ) # User hook features user_creator_features = FeatureView( name="user_creator_features", description="User creator features metrics including watch time of the user on the creator", entities=[user, creator], ttl=timedelta(days=30), # Keep features for 30 days schema=[ # For multi-entity feature views, include both entity columns Field(name="USER_ID", dtype=Int64), Field(name="CREATOR_ID", dtype=String), Field( name="AVERAGE_WATCH_TIME_30D", dtype=Float32, description="Average watch time in seconds across all hooks created by the creator", ), Field( name="NUM_LIKED_HOOKS_30D", dtype=Int64, description="Number of distinct hooks liked by the user for this creator in the last 30 days", ), Field( name="NUM_DISLIKED_HOOKS_30D", dtype=Int64, description="Number of distinct hooks disliked by the user for this creator in the last 30 days", ), Field( name="HAS_FOLLOWED_CREATOR_30D", dtype=Int64, description="Has the user followed the creator in the last 30 days (1 if followed, -1 if unfollowed)", ), ], source=user_creator_features_source, online=True, # Available for online serving tags={"team": "recs"}, )