23 lines
768 B
JavaScript
23 lines
768 B
JavaScript
|
|
class MemoryOptimizer {
|
|
constructor(options = {}) {
|
|
this.threshold = options.threshold || 0.3;
|
|
this.decayRate = options.decayRate || 0.01;
|
|
this.lastRun = Date.now();
|
|
}
|
|
optimize(memories) {
|
|
const now = Date.now();
|
|
const elapsed = (now - this.lastRun) / 1000;
|
|
this.lastRun = now;
|
|
|
|
console.log(`Optimizing ${memories.length} memories...`);
|
|
|
|
return memories.map(m => {
|
|
// Temporal decay: strength drops over time unless reinforced
|
|
const decay = m.importance * this.decayRate * elapsed;
|
|
return { ...m, strength: Math.max(0, m.strength - decay) };
|
|
}).filter(m => m.strength > this.threshold || m.locked);
|
|
}
|
|
}
|
|
export default MemoryOptimizer;
|