diff --git a/go/internal/storage/lancedb_ipc.go b/go/internal/storage/lancedb_ipc.go index 1853dde..292d17a 100644 --- a/go/internal/storage/lancedb_ipc.go +++ b/go/internal/storage/lancedb_ipc.go @@ -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 } diff --git a/go/internal/storage/recall.go b/go/internal/storage/recall.go index 2826d91..396c780 100644 --- a/go/internal/storage/recall.go +++ b/go/internal/storage/recall.go @@ -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)