update_predictions โ
Refresh prediction scores for a project's contexts.
Overview โ
The update_predictions tool is part of Layer 3 (Propagation Engine). It recalculates prediction scores for contexts that have stale predictions or no predictions yet.
Layer: Layer 3 - Propagation Engine (Future)
Purpose: Keep prediction scores fresh and accurate
Temporal Focus: Future - predicting what will be needed
Parameters โ
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
project | string | Yes | - | Project to update predictions for |
staleThreshold | number | No | 24 | Hours before prediction is considered stale |
Parameter Details โ
project โ
The project identifier to update predictions for.
staleThreshold โ
How old (in hours) a prediction can be before it's refreshed. Lower values = more aggressive updates.
Examples:
6: Refresh predictions older than 6 hours (aggressive)24: Refresh daily (default, balanced)168: Refresh weekly (conservative)
Returns โ
Formatted text with update count:
๐ฎ Updated predictions for authentication-refactor
Refreshed 15 prediction(s) (stale threshold: 24 hours)Examples โ
Basic Usage โ
update_predictions({
project: "api-service"
})Updates predictions older than 24 hours.
Aggressive Updates โ
update_predictions({
project: "critical-project",
staleThreshold: 6
})Refresh predictions every 6 hours for maximum accuracy.
After Heavy Activity โ
// After saving many contexts
save_context({ project: "my-project", content: "..." });
save_context({ project: "my-project", content: "..." });
save_context({ project: "my-project", content: "..." });
// Refresh predictions to reflect new access patterns
update_predictions({ project: "my-project" });Use Cases โ
1. Scheduled Maintenance โ
Keep predictions fresh automatically:
// Every 12 hours
cron.schedule('0 */12 * * *', async () => {
update_predictions({
project: "main-project",
staleThreshold: 12
});
});2. After Major Changes โ
Refresh after significant activity:
// Completed a big feature
completeFeature();
// Update predictions to reflect new patterns
update_predictions({ project: "feature-x" });3. Pre-Loading Optimization โ
Update before querying high-value contexts:
// Refresh predictions
update_predictions({ project: "my-project" });
// Then get high-value contexts
get_high_value_contexts({ project: "my-project" });Prediction Scoring โ
When predictions are updated, each context gets a score (0.0-1.0) based on:
Temporal Score (40% weight) โ
- Recently accessed โ High score
- Not accessed in weeks โ Low score
Causal Score (30% weight) โ
- Root causes โ High score
- Leaf nodes โ Lower score
- Decision nodes โ Bonus points
Frequency Score (30% weight) โ
- High access count โ High score
- Rarely accessed โ Low score
Combined:
prediction_score = (
temporal_score * 0.4 +
causal_score * 0.3 +
frequency_score * 0.3
)Staleness Detection โ
A prediction is stale if:
hours_since_prediction >= staleThresholdWhy predictions become stale:
- Access patterns changed
- New contexts added
- Time passed (temporal score decays)
Performance โ
| Contexts | Latency | Notes |
|---|---|---|
| 10 | 50-100ms | Fast |
| 50 | 200-500ms | Moderate |
| 100+ | 500ms-2s | Batch processing |
Optimization:
- Only updates stale predictions (not all contexts)
- Processes in batches
- Runs async (non-blocking)
Integration with Layer 3 โ
Before Get High-Value Contexts โ
// Ensure predictions are fresh
update_predictions({ project: "my-project" });
// Get accurate high-value contexts
get_high_value_contexts({
project: "my-project",
minScore: 0.7
});After Access Pattern Changes โ
// User accessed many old contexts
load_context({ project: "my-project", limit: 50 });
// This changed access patterns
// Update predictions to reflect new patterns
update_predictions({ project: "my-project" });Monitor Prediction Quality โ
// Update predictions
update_predictions({ project: "my-project" });
// Check quality
get_propagation_stats({ project: "my-project" });
// Shows average prediction score, coverage, etc.Best Practices โ
1. Run Regularly โ
// โ
Good: Scheduled updates
cron.schedule('0 0 * * *', () => {
update_predictions({ project: "my-project" });
});
// โ Bad: Never updating
// Predictions become stale and inaccurate2. Balance Freshness vs Performance โ
// โ
Good: Daily updates (balanced)
update_predictions({ project: "my-project", staleThreshold: 24 });
// โ ๏ธ Aggressive: Hourly (high cost)
update_predictions({ project: "my-project", staleThreshold: 1 });
// โ ๏ธ Conservative: Weekly (stale data)
update_predictions({ project: "my-project", staleThreshold: 168 });3. Update After Bulk Operations โ
// Batch save
for (const item of items) {
save_context({ project: "my-project", content: item });
}
// Update predictions once after batch
update_predictions({ project: "my-project" });Metadata Updated โ
When predictions are updated, these fields are set:
UPDATE context_snapshots SET
prediction_score = <calculated_score>,
last_predicted = datetime('now'),
propagation_reason = <json_array_of_reasons>
WHERE ...Fields:
prediction_score: 0.0 to 1.0last_predicted: ISO timestamppropagation_reason: JSON array like["recently_accessed", "causal_chain_root"]
See Also โ
- get_high_value_contexts - Use predictions
- get_propagation_stats - Monitor prediction quality
- Layer 3: Propagation Engine - Understanding predictions
- Database Schema - Prediction columns
