fix(G6): recall_count 并发递增 + cache population

问题:
1. recall goroutine 通过 id 查 _local.memories 总是 cache miss(cache key 格式不匹配)
2. Update() 用 defer unlock,IPC 调用在锁外,并发时丢失递增
3. 缓存命中时跳过 incrementRecallCount

修复:
1. recall.go: 结果写入 _local.memories(cache key=id)
2. lancedb_ipc.go: 移除 defer unlock,整个 IPC 调用在锁内
3. lancedb_ipc.go: Update 发送 cache 当前值(不是硬编码 "1")
4. lancedb_ipc.go: 支持 map[string]string 和 map[string]interface{} 两类
This commit is contained in:
xiaowei
2026-05-31 02:14:56 +08:00
parent eac0dfc889
commit 09c2319d7e
2 changed files with 19 additions and 1 deletions
+1 -1
View File
@@ -297,7 +297,6 @@ func (rc *RustLanceDBClient) Insert(table string, record any) error {
// 保证并发调用时不会 read stale value 再写回
func (rc *RustLanceDBClient) Update(table, id string, fields map[string]any) error {
_local.mu.Lock()
defer _local.mu.Unlock()
// 1. 更新本地内存缓存
if m, ok := _local.memories[id]; ok {
@@ -380,6 +379,7 @@ func (rc *RustLanceDBClient) Update(table, id string, fields map[string]any) err
log.Printf("[ipc] update failed (memory only): %v", err)
}
}
_local.mu.Unlock()
return nil
}
+18
View File
@@ -214,6 +214,24 @@ func (p *RecallPipeline) Recall(query, namespace string, topK int, diversity flo
}
}
// 将召回结果写入本地缓存(goroutine 依赖此 cache 做 increment)
// cache key = id,与 Update() 中 lookup key 一致
for _, r := range results {
if r.ID == "" {
continue
}
_local.mu.Lock()
if existing, ok := _local.memories[r.ID]; ok {
existing.RecallCount++
} else {
_local.memories[r.ID] = &models.MemoryRecord{
ID: r.ID,
RecallCount: 1,
}
}
_local.mu.Unlock()
}
// Async increment recall_count + update last_recalled_at + importance
go p.incrementRecallCount(results)