fix(recall): Embedder http client 8s 超时 + decay 分批 AC-1 日志
- Embedder http.Client{} 无超时 → 远端 bge 半开 TCP 时 recall 永久挂起
(gateway 10s 断 → 织忆异常误报)。加 8s 超时快速失败降级。
- decay 每 tick 限量 2000 条(最久未访问优先) + scanned/forgotten 日志
(AC-1 验收证据)
This commit is contained in:
parent
4376f1f2ce
commit
e67f0bc7a6
|
|
@ -1249,6 +1249,8 @@ func NewServer() http.Handler {
|
|||
// 最久未访问的(last_recalled_at 最早 → 最该遗忘),防全表单次拉取
|
||||
// 内存翻倍 + 长时间阻塞触发器循环。
|
||||
memories, e := ldb.GetCandidatesForForgetting()
|
||||
decayScanned := 0
|
||||
decayForgotten := 0
|
||||
if e == nil {
|
||||
const maxDecayBatch = 2000
|
||||
if len(memories) > maxDecayBatch {
|
||||
|
|
@ -1259,6 +1261,7 @@ func NewServer() http.Handler {
|
|||
memories = memories[:maxDecayBatch]
|
||||
}
|
||||
for _, m := range memories {
|
||||
decayScanned++
|
||||
// 解析 last_recalled_at
|
||||
lastAccessed := time.Now().Add(-30 * 24 * time.Hour) // 默认30天前
|
||||
if t, ok := m["last_recalled_at"].(string); ok && t != "" {
|
||||
|
|
@ -1288,9 +1291,14 @@ func NewServer() http.Handler {
|
|||
forgetter.ScanAndForget(id)
|
||||
// 实际执行软删除(持久化到 LanceDB)
|
||||
_ = ldb.SoftDelete(id, "auto_forget")
|
||||
decayForgotten++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// AC-1 验收日志(P1 修复 type 断言后 last_recalled_at 可解析;batch<=2000)
|
||||
if decayScanned > 0 {
|
||||
log.Printf("[decay] scanned=%d forgotten=%d (batch<=2000, 最久未访问优先)", decayScanned, decayForgotten)
|
||||
}
|
||||
case "gap_scan":
|
||||
// 检查已有缺口:过期 7 天的自动关闭
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Embedder bge-m3 编码客户端。优先使用本地 vLLM(端口 8000),fallback 到模力方舟 API。
|
||||
|
|
@ -33,7 +34,7 @@ func NewEmbedder(endpoint string) *Embedder {
|
|||
endpoint: endpoint,
|
||||
modelName: getModelName(),
|
||||
apiKey: os.Getenv("MOLIFANG_API_KEY"),
|
||||
httpClient: &http.Client{},
|
||||
httpClient: &http.Client{Timeout: 8 * time.Second},
|
||||
dim: 1024,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue