Files
Cyrene_v2/internal/runtime/memory/decay.go
T
AskaEth 61cf80d5ee
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled
docs(comments): 注释中文化 · internal/runtime/memory(31 文件,纯替换)
- 只翻注释/文档字符串:820 增 / 820 删 严格 1:1;剥掉整行注释与行尾注释尾巴后,
  逐文件与 HEAD 比对「代码部分差异 = 0」;裁决/design 编号计数逐项与 HEAD 一致
- 保留可执行 SQL 样例、SQLite 报错原文、pgvector/HNSW/ANN/BLOB 等技术词原文
- 复核:go build 绿 + memory/projectindex/vector 三包测试绿;gofmt 仅剩 2 个既有未格式化文件(改动前即如此,未顺手修)
2026-10-04 13:32:54 +08:00

24 lines
797 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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)
}