🧭 Do not search for the first 15 minutes. When stuck: re-read the requirements → define I/O → choose the data structure → trace a small example by hand → write code.
Implement a FeatureStore that saves and serves per-entity feature values in
front of model serving. The whole problem is honoring the API contract exactly —
skim the spec and you will get it wrong.
store = FeatureStore()
store.set("user1", "clicks", 10)
store.set("user1", "purchases", 2)
store.get("user1", "clicks") # 10
store.get_all("user1") # {"clicks": 10, "purchases": 2}
user1) and feature names (clicks) are strings.| Call | When missing |
|---|---|
get(entity, feature) | None |
get_all(entity) | an empty dictionary (not None) |
delete(entity, feature) | does nothing (never raises) |
increment(entity, feature, delta) | starts at 0 and adds delta |
get_all returns a copy. Mutating what it returns must not change the store.
| Level | Added requirement |
|---|---|
| 1 | set, get, get_all |
| 2 | increment, delete |
| 3 | entities(), snapshot() — whole-store reads |
Each level must preserve the behavior of the previous ones.
FeatureStore()
set(entity: str, feature: str, value) -> None
get(entity: str, feature: str) # None when missing
get_all(entity: str) -> dict # {} when missing
set to an existing key overwrites it.get_all returns every feature of that entity as {feature name: value}.get_all returned must not affect the store (return a copy).get_all on an entity that was never stored returns an empty dictionary.