docs(comments): 注释中文化 · internal/runtime/memory(31 文件,纯替换)
- 只翻注释/文档字符串:820 增 / 820 删 严格 1:1;剥掉整行注释与行尾注释尾巴后, 逐文件与 HEAD 比对「代码部分差异 = 0」;裁决/design 编号计数逐项与 HEAD 一致 - 保留可执行 SQL 样例、SQLite 报错原文、pgvector/HNSW/ANN/BLOB 等技术词原文 - 复核:go build 绿 + memory/projectindex/vector 三包测试绿;gofmt 仅剩 2 个既有未格式化文件(改动前即如此,未顺手修)
This commit is contained in:
1 parent
eb1828ee7a
commit
61cf80d5ee
31 files changed
+820
-820
No files matched your search
@@ -9,47 +9,47 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrNilAdapter is returned when an LLMExtractor is built or used without a
|
||||
// model.Adapter to drive extraction.
|
||||
// ErrNilAdapter 在构建或使用 LLMExtractor 却未提供
|
||||
// 驱动提取的 model.Adapter 时返回。
|
||||
ErrNilAdapter = errors.New("memory: nil model adapter")
|
||||
)
|
||||
|
||||
// Extractor derives candidate memory items from a conversation (design §1).
|
||||
// Extractor 从一次对话中推导候选记忆条目(design §1)。
|
||||
//
|
||||
// Two implementations exist:
|
||||
// 有两个实现:
|
||||
//
|
||||
// - LLMExtractor: asks a model.Adapter to denoise and deduplicate each turn,
|
||||
// running synchronously (Extract) or on a background goroutine
|
||||
// (ExtractAsync).
|
||||
// - ManualExtractor: deterministic, rule-based — it only records what the user
|
||||
// explicitly asks to remember ("记住 X").
|
||||
// - LLMExtractor:让 model.Adapter 对每轮对话去噪去重,
|
||||
// 同步运行(Extract)或在后台 goroutine 上运行
|
||||
// (ExtractAsync)。
|
||||
// - ManualExtractor:确定性、规则式 —— 只记录用户
|
||||
// 显式要求记住的内容(「记住 X」)。
|
||||
type Extractor interface {
|
||||
// Extract returns memory items worth persisting from conversation. ctx
|
||||
// controls cancellation; a canceled context returns an error.
|
||||
// Extract 返回对话中值得持久化的记忆条目。ctx
|
||||
// 控制取消;ctx 被取消时返回错误。
|
||||
Extract(ctx context.Context, conversation []model.Message) ([]MemoryItem, error)
|
||||
}
|
||||
|
||||
// ManualExtractor implements the manual "记住 X" extraction path without an LLM.
|
||||
// It scans user turns for a leading remember directive and produces a memory
|
||||
// item for each, falling back to no item for ordinary dialogue. It is the
|
||||
// deterministic counterpart to the M4 LLM extractor.
|
||||
// ManualExtractor 实现不经 LLM 的手动「记住 X」提取路径。
|
||||
// 它扫描用户轮次中领起的记住指令,为每条产出一个记忆
|
||||
// 条目,普通对话则不产出。它是 M4 LLM 提取器的
|
||||
// 确定性对照实现。
|
||||
type ManualExtractor struct {
|
||||
personaID string
|
||||
roleID string
|
||||
}
|
||||
|
||||
// NewManualExtractor builds a ManualExtractor whose extracted items carry
|
||||
// personaID/roleID as their author. Like the LLM extractor, the persona is a
|
||||
// default rather than the authority: a multi-role caller builds it with a blank
|
||||
// persona and stamps each item with the turn's role when persisting it
|
||||
// (design/22 §4.2), so pass "" for a role-agnostic extractor.
|
||||
// NewManualExtractor 构建 ManualExtractor,其提取出的条目以
|
||||
// personaID/roleID 为作者。与 LLM 提取器一样,角色是
|
||||
// 默认值而非权威:多角色调用方以空
|
||||
// 角色构建它,并在持久化时用该轮的角色给条目盖章
|
||||
// (design/22 §4.2),因此要构建与角色无关的提取器就传 ""。
|
||||
func NewManualExtractor(personaID, roleID string) *ManualExtractor {
|
||||
return &ManualExtractor{personaID: personaID, roleID: roleID}
|
||||
}
|
||||
|
||||
// Extract returns one memory item (kind relationship, persona scope) per user
|
||||
// turn that asks the agent to remember something. A leading "记住"/"请记住"
|
||||
// directive is stripped from the stored content; turns without one are skipped.
|
||||
// Extract 为每个要求代理记住点什么的用户
|
||||
// 轮次返回一条记忆条目(kind 为 relationship、作用域为 persona)。领起的
|
||||
// 「记住」/「请记住」指令会从落库内容中剥离;没有该指令的轮次跳过。
|
||||
func (e *ManualExtractor) Extract(ctx context.Context, conversation []model.Message) ([]MemoryItem, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
@@ -77,9 +77,9 @@ func (e *ManualExtractor) Extract(ctx context.Context, conversation []model.Mess
|
||||
return items, nil
|
||||
}
|
||||
|
||||
// rememberDirective strips the "记住" / "请记住" prefix when text is a remember
|
||||
// instruction. It returns the remembered content and true, or ok=false when the
|
||||
// text is not an explicit remember request.
|
||||
// rememberDirective 在 text 是记住指令时剥离「记住」/「请记住」前缀。
|
||||
// 它返回被记住的内容与 true;text 不是显式记住请求时
|
||||
// ok=false。
|
||||
func rememberDirective(text string) (string, bool) {
|
||||
for _, prefix := range []string{"请记住", "记住"} {
|
||||
if strings.HasPrefix(text, prefix) {
|
||||
|
||||
Reference in new issue
Block a user