19 lines
632 B
JavaScript
19 lines
632 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;
|
|
return memories.map(m => {
|
|
const decay = (m.importance || 1) * this.decayRate * elapsed;
|
|
return { ...m, strength: Math.max(0, (m.strength || 1) - decay) };
|
|
}).filter(m => m.strength > this.threshold || m.locked);
|
|
}
|
|
}
|
|
export default MemoryOptimizer;
|