Feature Store Lookup
Feature Store Lookup
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.
Lookup Rules
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.
Examples
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.
Hint 1
Python dicts have a .get(key, default) method that returns the default when the key is missing.
Hint 2
The {**dict1, **dict2} syntax merges two dicts into a new one without mutating either source.
Requirements
- Look up offline features for each request's user ID
- Use default values when the user is not found in the feature store
- Merge offline and online features into one dict per request
- Return results in the same order as the input requests
Constraints
- 1 ≤ len(requests) ≤ 10000
- Feature values are floats
- Offline and online feature keys do not overlap
- All user IDs are strings
- Time limit: 300 ms
Log in to take notes on this problem
Accepts: any
Accepts: array
Accepts: any
Feature Store Lookup
Feature Store Lookup
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.
Lookup Rules
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.
Examples
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.
Hint 1
Python dicts have a .get(key, default) method that returns the default when the key is missing.
Hint 2
The {**dict1, **dict2} syntax merges two dicts into a new one without mutating either source.
Requirements
- Look up offline features for each request's user ID
- Use default values when the user is not found in the feature store
- Merge offline and online features into one dict per request
- Return results in the same order as the input requests
Constraints
- 1 ≤ len(requests) ≤ 10000
- Feature values are floats
- Offline and online feature keys do not overlap
- All user IDs are strings
- Time limit: 300 ms
Log in to take notes on this problem
Accepts: any
Accepts: array
Accepts: any