Skip to content

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 โ€‹

ParameterTypeRequiredDefaultDescription
projectstringYes-Project to update predictions for
staleThresholdnumberNo24Hours 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 โ€‹

typescript
update_predictions({
  project: "api-service"
})

Updates predictions older than 24 hours.


Aggressive Updates โ€‹

typescript
update_predictions({
  project: "critical-project",
  staleThreshold: 6
})

Refresh predictions every 6 hours for maximum accuracy.


After Heavy Activity โ€‹

typescript
// 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:

typescript
// Every 12 hours
cron.schedule('0 */12 * * *', async () => {
  update_predictions({
    project: "main-project",
    staleThreshold: 12
  });
});

2. After Major Changes โ€‹

Refresh after significant activity:

typescript
// 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:

typescript
// 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 >= staleThreshold

Why predictions become stale:

  • Access patterns changed
  • New contexts added
  • Time passed (temporal score decays)

Performance โ€‹

ContextsLatencyNotes
1050-100msFast
50200-500msModerate
100+500ms-2sBatch 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 โ€‹

typescript
// 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 โ€‹

typescript
// 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 โ€‹

typescript
// 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 โ€‹

typescript
// โœ… Good: Scheduled updates
cron.schedule('0 0 * * *', () => {
  update_predictions({ project: "my-project" });
});

// โŒ Bad: Never updating
// Predictions become stale and inaccurate

2. Balance Freshness vs Performance โ€‹

typescript
// โœ… 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 โ€‹

typescript
// 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:

sql
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.0
  • last_predicted: ISO timestamp
  • propagation_reason: JSON array like ["recently_accessed", "causal_chain_root"]

See Also โ€‹