Help us shape the future of Go! Take the 2026 Go Developer Survey

memory

package
v1.38.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package memory 提供 AI 助手的持久记忆(借鉴 zcode memory extraction/recall)。

目标:让助手跨会话记住「哪类失败怎么处理」「用户偏好」「高频任务」, 而不是每次都从零推理。存储为 data/ai-memory.json,结构简单可审计。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	ID        string    `json:"id"`
	Kind      Kind      `json:"kind"`
	Content   string    `json:"content"`
	Tags      []string  `json:"tags,omitempty"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	UseCount  int       `json:"use_count"`
}

Entry 一条记忆。

type Kind

type Kind string

Kind 记忆类型。

const (
	KindPreference Kind = "preference" // 用户偏好/约定
	KindPattern    Kind = "pattern"    // 故障模式与处置
	KindFact       Kind = "fact"       // 环境/仓库事实
	KindTask       Kind = "task"       // 待办/约定动作
)

type Store

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

Store 文件型记忆库(并发安全)。

func Open

func Open(path string) (*Store, error)

Open 打开(不存在则空库)。

func (*Store) Forget

func (s *Store) Forget(id string) bool

Forget 按 ID 删除。

func (*Store) Manifest

func (s *Store) Manifest(limit int) string

Manifest 供注入 system prompt 的摘要。

func (*Store) Recall

func (s *Store) Recall(query string, limit int) []Entry

Recall 按关键字/标签召回,最多 limit 条。 score: 命中标签>命中内容>全部;同分按更新时间倒序。

func (*Store) Remember

func (s *Store) Remember(kind Kind, content string, tags []string) (*Entry, error)

Remember 写入一条记忆;content 为空不写。同 Kind+Content 视为更新。

Jump to

Keyboard shortcuts

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