Knowledge Freshness and Temporal Updates › Visualizing Staleness Over Time
Language AI HandbookAll chapters The simulation gives 40 fast-changing and 40 slow-changing facts independent daily chances of changing. Each change produces a new value. On a refresh day, the index synchronizes after that day's changes, so the stale fraction resets to zero.
PythonIn [24]Expand
import numpy as np
def simulate_staleness(
n_days=180, refresh_every=14, n_fast=40, n_slow=40, seed=1
):
"""Average fraction of facts that are stale on each day.
The mean wait for a change is 20 days for fast facts and 400 for slow facts.
index fixed-refresh every 'refresh_every' days.
"""
r = np.random.default_rng(seed)
# Per-fact change probability per day.
p_fast = 1.0 / 20.0
p_slow = 1.0 / 400.0
stale_fast = np.zeros(n_days)
stale_slow = np.zeros(n_days)
for f in range(n_fast):
last_sync_value = 0
true_value = 0
for d in range(n_days):
if r.random() < p_fast:
true_value += 1
if d % refresh_every == 0:
last_sync_value = true_value
stale_fast[d] += true_value != last_sync_value
for f in range(n_slow):
last_sync_value = 0
true_value = 0
for d in range(n_days):
if r.random() < p_slow:
true_value += 1
if d % refresh_every == 0:
last_sync_value = true_value
stale_slow[d] += true_value != last_sync_value
return stale_fast / n_fast, stale_slow / n_slow
fast_stale, slow_stale = simulate_staleness()
days = np.arange(len(fast_stale))VisualizationOut [25]Expand

After independent daily opportunities for change since a refresh, a fact is stale with probability , where is its daily change probability. At day 13 this is about 49% for and 3% for . Those are expectations under the illustrative model. Daily sample proportions vary. Choose cadences against measured change rates and acceptable staleness.
The calculation follows from the complement event. At age zero the index already includes the current value, so staleness is zero. With s elapsed daily change opportunities, all s must pass without an update for the cached value to remain current in this nonreverting model. Multiply their unchanged probabilities, then subtract from one. The maximum age within a full 14-day cycle is 13 days because the next refresh resets the age. A process that returns to an earlier value, queues updates, or has dependent changes needs a different probability model.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!