feat(memory): M4 记忆完善(三类作用域访问规则+项目索引分层+LLM异步提取+衰减溯源+向量接入,兼容既有57用例)

This commit is contained in:
Aska committed 2026-09-06 06:15:18 +08:00
1 parent 5b37f5a551
commit d947ec41a9
10 files changed
+1349 -53

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
package memory
import (
"math"
"time"
)
// decayFactor computes the decay multiplier for a single item: the stored
// decay_weight scaled by a time-decay that halves every recencyHalfLife days
// (design §2 衰减: 久未使用的记忆降权). A freshly touched item keeps its full
// decay_weight; an item unused for N half-lives is scaled to
// decay_weight * 0.5^N, so it ranks progressively lower unless it stays relevant.
//
// age is measured from UpdatedAt; a future timestamp (clock skew) is clamped to
// zero, so a just-recorded item is never scored above its base weight.
func (r *Retriever) decayFactor(it MemoryItem, now time.Time) float64 {
age := now.Sub(it.UpdatedAt)
if age < 0 {
age = 0
}
halfLives := float64(age) / float64(r.recencyHalfLife)
return it.DecayWeight * math.Pow(0.5, halfLives)
}