A Fast Feature Lookup Still Has to Mean the Right Thing
A model needs the right entity, feature definition and available measurements in a fixed order. Use a serving document for that contract while keeping historical training evidence separately.
15 sections · 4 questions · 1 coding challenge
The arrow keys move between sections too.
Separating Fast Current Lookups from Reproducible Training History
BOTIE
Our maintenance system already has historical SQL feature logic. Here we decide what a current serving lookup must return and which checks belong between that lookup and the model. The storage format is useful only if it preserves the feature contract.
The Model Received a Reading Quickly. Was It the Right Reading?
Botie’s fault model expects temperature followed by vibration. A fast key lookup returns the fields in a different order, using an older feature definition. The storage request succeeded, but the input no longer means what the model was trained to interpret.
The database choice follows the task. We will assemble a serving record only when its identity, definition and freshness match the model request, and retain an explicit fallback when they do not.
Invented maintenance records. These deterministic local models expose a storage decision; they do not run a distributed database or establish its guarantees.
Step 1 of 1
The same values in the wrong positions are different model inputs
The model contract names the positions explicitly.
| Position | Required feature | Document value |
|---|---|---|
| 0 | temperature | 30 |
| 1 | vibration | 0.8 |
0
- Required feature
- temperature
- Document value
- 30
1
- Required feature
- vibration
- Document value
- 0.8
A storage success is only the start of an input check
A found document becomes a prediction input only after its meaning, time and named values satisfy the declared contract.
Check the document before handing values to the model
Match the entity and feature definition, check decision-time availability and age, then assemble the names in the model’s required order.
BOTIE
Prediction route and ordered features
{
"route": "predict",
"vector": [
30,
0.8
]
}Follow the operations
1. Retrieved serving document
{ "tenant": "north", "asset": "P7", "feature_version": "bearing-v2", "event_time": 100, "available_time": 105, "features": { "vibration": 0.8, "temperature": 30 } }2. Authorised model request
{ "tenant": "north", "asset": "P7", "feature_version": "bearing-v2", "as_of": 110, "max_age": 20 }3. Match entity and feature definition
{ "context_ok": true, "record": { "tenant": "north", "asset": "P7", "feature_version": "bearing-v2", "event_time": 100, "available_time": 105, "features": { "vibration": 0.8, "temperature": 30 } } }4. Check availability and measurement age
{ "usable": true, "features": { "vibration": 0.8, "temperature": 30 } }5. Model feature order
- 0temperature
- 1vibration
6. Assemble the model's named inputs
{ "route": "predict", "vector": [ 30, 0.8 ] }7. Result
{ "route": "predict", "vector": [ 30, 0.8 ] }
The fixture checks a supplied document. It does not authenticate users, fetch historical versions, train a model or establish production safety.
1. Choose a store from the operation you need
A keyed serving record can be useful when the request already knows the tenant and asset and needs a small fixed set of inputs quickly. A document can keep related feature values and their metadata together. A relational table can also serve keyed reads; measure the existing system before introducing another database.
A fleet-wide historical training join has a different access pattern. Keep the source of truth, derived feature view and serving copy distinct in the design so each has an owner and a rebuild path.
The exercise does not rank database brands. It exposes the contract that any chosen serving path must meet.
2. Name the feature definition that produced the values
A feature name can remain the same while its meaning changes. Vibration might move from a raw reading to an average over a different time window. Units, missing-value rules and preprocessing can also change. Record a version or digest for the definition expected by the deployed model.
The feature definition version is separate from the document schema and source record revision. Compatible field shapes do not prove compatible model inputs. Reject or adapt a mismatch under an explicit policy instead of treating every readable dictionary as usable.
Our request requires bearing-v2 exactly. The fixture does not implement semantic version negotiation.
3. Keep observation time and availability time visible
Event time tells us when the measurement describes the asset. Availability time tells us when that value became usable by this serving path. An old event can arrive after the decision it is meant to support.
The earlier SQL lesson showed historical point-in-time selection. This lesson checks one retrieved document against a decision time and a maximum measurement age. It cannot reconstruct an overwritten historical value; if the current record fails, the route stays fallback unless another authorised source supplies suitable evidence.
A lookup of today’s latest document is not a historical training query.
Check a late arrival against an earlier decision
The event existed in the world before the decision, but the serving path received it afterward.
event_time = 100
available_time = 115
decision_time = 110
print(event_time <= decision_time)
print(available_time <= decision_time)True
FalseThe measurement’s event time alone would admit information the service did not yet have.
4. Assemble by the declared names, never by dictionary order
The model supplies an ordered feature-name list. Read each required name from the document in that order. Check for absent, nonnumeric and nonfinite values before constructing the vector. Extra document fields should not silently become model inputs.
A missing value policy belongs to the model’s definition. If training used a particular imputation rule, serving must use the compatible rule. Our exercise has no trained imputer, so it falls back rather than inventing a zero.
The vector’s positions are part of its meaning, even when all its entries are valid numbers.
Check yourself
Questions on Parts 1 to 4
Question 1 of 2
Can this serving record support that decision under the stated availability rule?
Use the information below.
The record’s event time is 100, availability time is 115 and the decision time is 110.5. Scope the lookup and retain its actual read contract
The authenticated service establishes tenant scope and builds the permitted key. It should use credentials limited to the needed records and operations. A browser should call the application boundary rather than receive broad storage credentials.
The read mode must suit the operation. A stronger table read can reduce one kind of staleness, but it cannot refresh a feature pipeline that has not produced a new document. Check the measurement metadata even when the storage read succeeds.
This external reference obtains a document. It deliberately leaves the application’s feature checks as a separate step.
Run in your own environment
Read a development serving document by its complete key
The prepared table has string partition key pk. Trusted tenant and asset values must come from the authorised application context.
External setup: install boto3 and provision a disposable development table with the stated key and an example feature item.
Use an authorised SDK role with the required read permission. The browser challenge performs no network calls.
import boto3
table = boto3.resource("dynamodb", region_name="us-east-1").Table("maintenance_features_dev")
response = table.get_item(
Key={"pk":"tenant:north:asset:P7"},
ConsistentRead=True,
)
item = response.get("Item")
print(item is not None)A found item still needs entity, definition, availability, age and value checks. Key encoding also needs a collision-free production convention.
Official implementation documentation. Documentation checked .
6. Keep an explicit outcome when the feature contract fails
A missing document, wrong feature version or stale measurement should not silently proceed to prediction. Decide whether the application can use a documented baseline, request a fresh measurement, or ask for human inspection. That decision depends on the task’s consequences.
Our function returns fallback with an empty vector. A production interface should record the reason without leaking another tenant’s data, and should make clear when it is showing a baseline rather than the requested model result.
A fallback is an application outcome. It is not evidence that the asset is healthy.
7. Retain enough evidence to reproduce the prediction
A compact serving record often keeps only the latest state. Retain an appropriate prediction log or immutable references that identify the model, feature definition and input data used, subject to privacy and retention requirements. An offline store can support historical reconstruction if its time and revision semantics are understood.
Compare training and serving transformations with shared cases. A correct training query cannot compensate for a serving adapter that changes units or feature order. Monitor missing inputs, age and version mismatches alongside model performance.
The record checks test input compatibility, not the accuracy or fairness of the trained model.
8. Change the feature system without losing its reconstruction path
A new feature definition may require a new serving namespace or an explicit versioned rollout. Backfill the required entities, compare representative predictions, and switch the model and feature contract together. Keep the earlier version long enough for the agreed rollback and audit needs.
If another database is added, account for its projection lag, rebuild process and access boundary. A smaller inference lookup can be worth that work, but a second current copy also creates another place whose freshness must be explained.
Botie now has a concrete boundary between finding a document and using it as model input.
Check yourself
Questions on Parts 1 to 8
Question 1 of 2
Which outcome matches this lesson’s contract?
Use the information below.
The requested model expects bearing-v2, but the current serving document is bearing-v1.Try it with Botie
Build with Botie
Write and run Python