memory

package
v0.6.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package memory 实现 Golem 的记忆管理系统,包括长期记忆 (MEMORY.md) 和基于日记的短期记忆。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DiaryEntry

type DiaryEntry struct {
	Date    string // 日期 (YYYY-MM-DD)
	Path    string // 文件路径
	Content string // 分录内容
}

DiaryEntry 表示单条日记分录。

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager 负责管理工作区内的记忆文件读写与上下文召回。

func NewManager

func NewManager(workspacePath string) *Manager

NewManager 为指定的工作区创建一个记忆管理器。

func (*Manager) AppendDiary

func (m *Manager) AppendDiary(entry string) (string, error)

AppendDiary 在当前日期的日记文件中追加一条记录。

func (*Manager) AppendDiaryAt

func (m *Manager) AppendDiaryAt(ts time.Time, entry string) (string, error)

AppendDiaryAt 在指定时间的日记文件中追加一条记录。

func (*Manager) Ensure

func (m *Manager) Ensure() error

Ensure 确保记忆目录和长期记忆文件存在。

func (*Manager) ReadDiary

func (m *Manager) ReadDiary(date string) (string, error)

ReadDiary 读取指定日期的日记内容。

func (*Manager) ReadLongTerm

func (m *Manager) ReadLongTerm() (string, error)

ReadLongTerm 读取长期记忆文件的全文内容。

func (*Manager) ReadRecentDiaries

func (m *Manager) ReadRecentDiaries(limit int) ([]DiaryEntry, error)

ReadRecentDiaries 读取最近几天的日记分录。

func (*Manager) RecallContext added in v0.5.0

func (m *Manager) RecallContext(query string, recentLimit, keywordLimit int) (RecallResult, error)

RecallContext 使用“最近优先 + 关键词命中”策略从记忆中检索相关的上下文片段。

func (*Manager) WriteLongTerm

func (m *Manager) WriteLongTerm(content string) error

WriteLongTerm 覆盖写入长期记忆文件。

type RecallItem added in v0.5.0

type RecallItem struct {
	Source  string // 来源(如 "diary_recent", "long_term")
	Date    string // 关联日期(可选)
	Path    string // 来源文件路径
	Excerpt string // 摘录内容
}

RecallItem 表示带来源归属的单条回忆片段。

type RecallResult added in v0.5.0

type RecallResult struct {
	Query       string         // 原始查询
	RecallCount int            // 召回的总片段数
	SourceHits  map[string]int // 各来源的命中统计
	Items       []RecallItem   // 召回的具体片段列表
}

RecallResult 总结了上下文回忆的质量和来源分布。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL