- 只翻注释/文档字符串:820 增 / 820 删 严格 1:1;剥掉整行注释与行尾注释尾巴后, 逐文件与 HEAD 比对「代码部分差异 = 0」;裁决/design 编号计数逐项与 HEAD 一致 - 保留可执行 SQL 样例、SQLite 报错原文、pgvector/HNSW/ANN/BLOB 等技术词原文 - 复核:go build 绿 + memory/projectindex/vector 三包测试绿;gofmt 仅剩 2 个既有未格式化文件(改动前即如此,未顺手修)
24 lines
797 B
Go
24 lines
797 B
Go
package memory
|
||
|
||
import (
|
||
"math"
|
||
"time"
|
||
)
|
||
|
||
// decayFactor 计算单条条目的衰减乘数:已存的
|
||
// decay_weight 乘以每 recencyHalfLife 天减半的时间衰减
|
||
// (design §2 衰减: 久未使用的记忆降权)。刚被触碰的条目保留完整的
|
||
// decay_weight;N 个半衰期未使用的条目被缩放到
|
||
// decay_weight * 0.5^N,因此除非持续相关,其排名会逐步下降。
|
||
//
|
||
// age 自 UpdatedAt 起算;未来时间戳(时钟偏移)被夹到
|
||
// 零,因此刚记录的条目得分绝不会高于其基础权重。
|
||
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)
|
||
}
|