mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-11-06 09:17:31 +00:00
fix(memory): graph_centroid 建表归位到 schemas —— 新库不再每轮回退
问题(WSL2 真机诊断报告问题 5):新库上每轮召回都打 `[graph] recall blocks: reading centroid failed, falling back to raw vectors: graph: load centroid: no such table: graph_centroid` 417KB 日志里占相当比例,并回退到全量 raw vectors 扫描(生产库 3178 块)。 根因不是"迁移脚本漏了",而是**建表根本没在初始化里**: graph_centroid 只定义在 centroid_store.go,且只由 SaveCentroid 内部的 ensureCentroidSchema 创建。新建的库在存过第一个中心向量之前**从不** 调 SaveCentroid ⇒ 建表语句一次没跑过;而召回走的是 LoadCentroid。 修法:把 ddlCentroid 加进 graph.go 的 schemas 列表(复用同一个常量, 避免两处 DDL 漂移)。 判据(centroid_store_test.go,2 条,均经变异验证): · TestGraphCentroidTableExistsOnNewDB —— 新建库后表必须已存在 · TestLoadCentroidOnNewDBDoesNotFail —— 空库 LoadCentroid 返回 (nil,false,nil) 而不是 error(贴真实故障路径) 变异:删掉 schemas 里那行 ddlCentroid ⇒ 两条全红,报错文案与真机一致。
This commit is contained in:
@ -408,6 +408,16 @@ func (g *GraphDB) initSchema() error {
|
||||
`CREATE INDEX IF NOT EXISTS idx_relation_type ON relations(relation_type)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_relation_status ON relations(status)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_relation_session ON relations(session_id)`,
|
||||
// ★ graph_centroid 必须在这里建(2026-10-25 修缺陷)。
|
||||
//
|
||||
// 此前它只由 SaveCentroid 内部的 ensureCentroidSchema 创建,
|
||||
// 而新建的库在存过第一个中心向量之前**从不**调 SaveCentroid。
|
||||
// 后果:LoadCentroid 每次召回都 `no such table: graph_centroid`,
|
||||
// 于是回退到全量 raw vectors 扫描——日志刷屏,且大库上明显变慢
|
||||
// (实测生产库 3178 块)。
|
||||
//
|
||||
// 复用 centroid_store.go 的同一个常量,避免两处 DDL 漂移。
|
||||
ddlCentroid,
|
||||
}
|
||||
|
||||
for _, s := range schemas {
|
||||
|
||||
Reference in New Issue
Block a user