Files
memoryweave/go/internal/storage/lancedb.go
T
小唯 1060e62066 fix(admin): /memories 与 /memories/export 改用全表扫描(Scan),弃零向量 ANN
病根:两个列表/导出端点一直用『零向量 ANN』冒充『列出全部』——零向量没有方向,
ANN 退化成本存储序前 N 行,再按 ns 客户端过滤 ⇒ 计数完全失真
(实测 export hermes-main 报 1 条,真实 139+;shared 报 0,真实 29)。

修复:
① Rust lancedb_ops: scan_for_forgetting 加 namespace 下推(only_if),limit 作用于过滤后结果集
② Go 接口 LanceDB 新增 Scan(limit, ns):
   - RustLanceDBClient → lancedb_scan RPC
   - SQLiteClient → SELECT ... WHERE is_deleted=0 [AND ns] ORDER BY created_at DESC LIMIT
   - MemLanceClient → 内存 map 过滤 + created_at 倒序
③ 两个端点 ListMemories / ExportMemoriesMD 改用 aa.LanceDB.Scan(limit, ns)
④ 补 mock(zz_commit mockLance / write-buffer fakeLDB)+ 5 条新判据
   (全表 3 / hermes-main 2 / shared 1 / limit 生效 / 不存在 ns 0)
2026-09-21 16:36:41 +08:00

42 lines
2.1 KiB
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.
// 织忆 MemoryWeave — LanceDB 接口定义
// 所有存储后端实现此接口,Go → Rust IPC 由 internal/consolidate 负责
package storage
import (
"github.com/xiaoxue/memoryweave/internal/models"
)
// VValueProvider 外部注入的 V 值查询函数(由 server.go 设置 → selfoptimize.VProp)
// 用于召回排序时融合用户决策信号
var VValueProvider func(memoryID string) float64
// LanceDB 存储后端统一接口
// 实现者: SQLiteClient (生产), MemLanceClient (开发/降级)
// 未来: Rust lancedb crate 通过 Unix Socket 提供 LanceDB 原生后端
type LanceDB interface {
InsertEpisode(agentID, namespace, content, category string) (string, error)
GetTopByQuality(agentID string, limit int) ([]models.MemoryRecord, error)
Stats() (map[string]interface{}, error)
SoftDelete(id, reason string) error
// SoftDeleteBatch 批量标记 is_deleted=true,updated_at=ts(单事务提交)
SoftDeleteBatch(table string, ids []string, updatedAt string) (int64, error)
GetVersionHistory(id string) ([]map[string]interface{}, error)
GetCandidatesForForgetting() ([]map[string]interface{}, error)
// G7.2: 获取适合结晶为 skill 的记忆候选
GetSkillCandidates(minRecalls, limit int) ([]models.MemoryRecord, error)
Backup(path string) error
GetAuditLog(limit int) ([]map[string]interface{}, error)
IncrementUseful(id string) error
IncrementNotUseful(id string) error
UpdateMemoryContent(id, newContent, source string) error
InsertMemory(m models.MemoryRecord) error
Search(table string, vector []float32, topK int, namespaceFilter string) ([]models.MemoryRecord, error)
// Scan 全表扫描存活记忆(is_deleted=false),按 namespace 可选过滤,跳向量。
// 2026-09-21:列表/导出端点的正确底座 —— 修前它们用「零向量 ANN」冒充列表,
// 零向量无方向 ⇒ 只拿到任意前 N 行再按 ns 过滤 ⇒ 计数完全失真。
Scan(limit int, namespaceFilter string) ([]models.MemoryRecord, error)
Insert(table string, record any) error
Update(table, id string, fields map[string]any) error
}