Files
memoryweave/go/internal/models/memory.go
T
xiaowei 40a8c9edee feat: E1 BFS 扩展 + 生产部署完整套件
E1 图谱导航:
- Add ExpandWithSummary (BFS 扩展 + LLM 汇总)
- Add GraphBFSResult/ExpandedRelation 模型
- Fix NavigateBiDir 伪实现问题 (docs/BFS_GRAPH_EXPANSION_DESIGN.md)

生产部署:
- README.md: 完整安装/配置/API 文档
- INSTALL.md: systemd 手动安装指南
- docker-compose.yml: 一键部署 (zhiyid + redis + bge-m3)
- Makefile: VERSION/version/build-web/install-all/docker-* 目标
- systemd: MemoryMax/CPUQuota 限制,完善环境变量

集成支持:
- eval_results.md: 性能基准测试报告
- scripts/benchmark.sh / benchmark.py: 可重复性能测试
- tests/integration_test.sh: 端到端集成测试

已知问题: graph/navigate 超时 (P0),见 eval_results.md
2026-06-02 18:58:38 +08:00

116 lines
4.3 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.
// Package models 定义织忆 MemoryWeave 的核心数据模型。
package models
import "time"
// Time 是 time.Time 的安全版本,支持空字符串解析
type Time struct{ time.Time }
// UnmarshalJSON 实现 json.Unmarshaler:空字符串解析为当前时间(而非报错)
func (t *Time) UnmarshalJSON(data []byte) error {
s := string(data)
if s == `""` || s == `"0001-01-01T00:00:00Z"` {
t.Time = time.Time{}
return nil
}
// 去掉前后引号
if len(s) >= 2 && s[0] == '"' && s[len(s)-1] == '"' {
s = s[1 : len(s)-1]
}
if s == "" || s == "null" {
t.Time = time.Time{}
return nil
}
return t.Time.UnmarshalJSON(data)
}
// VersionRecord 记忆版本记录(溯源链中的单次修改)
type VersionRecord struct {
Version int `json:"version"`
Content string `json:"content"`
UpdatedBy string `json:"updated_by"`
Source string `json:"source"`
Trigger string `json:"trigger"`
Reason string `json:"reason"`
Timestamp time.Time `json:"timestamp"`
}
// MemoryRecord 织忆中的单条记忆(存储在 LanceDB memories 表中)。
// v3.8 完整 Schema — 23 字段,与设计文档一致。
type MemoryRecord struct {
ID string `json:"id"`
AgentID string `json:"agent_id"`
Namespace string `json:"namespace"`
Content string `json:"content"`
ContentMD5 string `json:"content_md5"` // content 的 MD5 前 12 字符,用于精确去重
Category string `json:"category"` // system_fact, user_pref, proj_context, tool_usage, code_snippet
Vector []float32 `json:"vector"` // bge-m3 1024维,L2归一化
Tier string `json:"tier"` // normal, core(core永不衰减)
Importance float64 `json:"importance"` // 重要性得分 = recency_factor × (1+log(1+recall_count))
QualityScore float64 `json:"quality_score"`
UsefulCount int `json:"useful_count"` // 被标记 useful 的次数
NotUsefulCount int `json:"not_useful_count"` // 被标记 not-useful 的次数
Version int `json:"version"` // 当前版本号
VersionHistory []VersionRecord `json:"version_history,omitempty"` // 完整修改链
Source string `json:"source"` // 来源:牧尘口头 / 配置解析 / Agent推断 / LLM蒸馏
VolatileFlag bool `json:"volatile_flag"` // 频繁变更标记(≥3次修正自动设置)
RecallCount int `json:"recall_count"`
Freshness string `json:"freshness"` // fresh, stale, verified
LastRecalledAt time.Time `json:"last_recalled_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
IsDeleted bool `json:"is_deleted"`
DependsOn []string `json:"depends_on,omitempty"` // 依赖的记忆 ID 列表
DerivedFrom string `json:"derived_from,omitempty"` // 蒸馏来源 episode ID
}
// EpisodeRecord 原始对话/任务日志(存储在 LanceDB episodes 表中)。
type EpisodeRecord struct {
ID string `json:"id"`
AgentID string `json:"agent_id"`
Namespace string `json:"namespace"`
Content string `json:"content"`
Category string `json:"category"`
CreatedAt time.Time `json:"created_at"`
}
// TombstoneRecord 已删除/废弃记忆的墓碑记录。
type TombstoneRecord struct {
ID string `json:"id"`
OriginalID string `json:"original_id"`
Reason string `json:"reason"` // deprecated, merged, corrected, evicted
CreatedAt time.Time `json:"created_at"`
}
// RecallResult recall 接口返回的单条结果。
type RecallResult struct {
ID string `json:"id"`
Content string `json:"content"`
Category string `json:"category"`
Score float64 `json:"score"`
Timestamp string `json:"timestamp"`
}
// RerankResult rerank 重排后的单条结果。
type RerankResult struct {
Index int `json:"index"`
Score float64 `json:"score"`
Text string `json:"text"`
}
// GraphBFSResult BFS 图谱扩展结果(含汇总语句)
type GraphBFSResult struct {
ExpandedRelations []ExpandedRelation `json:"expanded_relations"`
Summary string `json:"summary"`
}
// ExpandedRelation 单条扩展关系
type ExpandedRelation struct {
From string `json:"from"`
To string `json:"to"`
Relation string `json:"relation"`
Hops int `json:"hops"`
Weight float64 `json:"weight"`
Score float64 `json:"score"`
}