You are building an ML inference pipeline. At prediction time, you need to join pre-computed user features (offline) from a feature store with real-time request features (online).
Given a feature store mapping user IDs to their offline features, a list of inference requests (each with a user ID and online features), and a set of default offline feature values for unknown users, return the combined feature vectors.
For each request, look up the user's offline features in the store. If the user is not found, use the provided defaults. Combine offline and online features into a single dict. Return one combined dict per request, in the same order as the input.
Input:
feature_store = {"user_1": {"avg_spend": 45.0, "total_orders": 12.0}} requests = [{"user_id": "user_1", "online_features": {"session_mins": 5.0, "pages_viewed": 8.0}}] defaults = {"avg_spend": 0.0, "total_orders": 0.0}
Output:
[{"avg_spend": 45.0, "total_orders": 12.0, "session_mins": 5.0, "pages_viewed": 8.0}]
user_1 is found in the store. Offline features are merged with request-time features.
Input:
feature_store = {"user_1": {"avg_spend": 45.0, "total_orders": 12.0}} requests = [{"user_id": "user_99", "online_features": {"session_mins": 1.0}}] defaults = {"avg_spend": 0.0, "total_orders": 0.0}
Output:
[{"avg_spend": 0.0, "total_orders": 0.0, "session_mins": 1.0}]
user_99 is not in the store, so default offline feature values are used.
Python dicts have a .get(key, default) method that returns the default when the key is missing.
The {**dict1, **dict2} syntax merges two dicts into a new one without mutating either source.
Sign in to take notes on this problem
Accepts: any
Accepts: array
Accepts: any
You are building an ML inference pipeline. At prediction time, you need to join pre-computed user features (offline) from a feature store with real-time request features (online).
Given a feature store mapping user IDs to their offline features, a list of inference requests (each with a user ID and online features), and a set of default offline feature values for unknown users, return the combined feature vectors.
For each request, look up the user's offline features in the store. If the user is not found, use the provided defaults. Combine offline and online features into a single dict. Return one combined dict per request, in the same order as the input.
Input:
feature_store = {"user_1": {"avg_spend": 45.0, "total_orders": 12.0}} requests = [{"user_id": "user_1", "online_features": {"session_mins": 5.0, "pages_viewed": 8.0}}] defaults = {"avg_spend": 0.0, "total_orders": 0.0}
Output:
[{"avg_spend": 45.0, "total_orders": 12.0, "session_mins": 5.0, "pages_viewed": 8.0}]
user_1 is found in the store. Offline features are merged with request-time features.
Input:
feature_store = {"user_1": {"avg_spend": 45.0, "total_orders": 12.0}} requests = [{"user_id": "user_99", "online_features": {"session_mins": 1.0}}] defaults = {"avg_spend": 0.0, "total_orders": 0.0}
Output:
[{"avg_spend": 0.0, "total_orders": 0.0, "session_mins": 1.0}]
user_99 is not in the store, so default offline feature values are used.
Python dicts have a .get(key, default) method that returns the default when the key is missing.
The {**dict1, **dict2} syntax merges two dicts into a new one without mutating either source.
Sign in to take notes on this problem
Accepts: any
Accepts: array
Accepts: any