Documentation
¶
Index ¶
- func EmbedderFunc(e Embedder) gorm.EmbeddingFunc
- type CompositeLongTermStore
- func (c *CompositeLongTermStore) AddHook(hook StoreHook)
- func (c *CompositeLongTermStore) AttachIndexer(indexer Indexer)
- func (c *CompositeLongTermStore) ClearSession(ctx context.Context, sessionID string) error
- func (c *CompositeLongTermStore) Close() error
- func (c *CompositeLongTermStore) GetRetriever() Retriever
- func (c *CompositeLongTermStore) GetSession(ctx context.Context, sessionID string) ([]*schema.Message, error)
- func (c *CompositeLongTermStore) GetStore() Store
- func (c *CompositeLongTermStore) IndexReady() bool
- func (c *CompositeLongTermStore) Recall(ctx context.Context, sessionID string, query string, topK int) ([]*schema.Message, error)
- func (c *CompositeLongTermStore) Save(ctx context.Context, sessionID string, msgs []*schema.Message) error
- type Controller
- func (c *Controller) AddSystemPrompt(msgs ...*schema.Message)
- func (c *Controller) BuildContext(ctx context.Context, sessionID string, currentQuery string) ([]*schema.Message, error)
- func (c *Controller) Clear(ctx context.Context, sessionID string) error
- func (c *Controller) Close() error
- func (c *Controller) GetHistory(ctx context.Context, sessionID string) ([]*schema.Message, error)
- func (c *Controller) GetShortMemory() ShortMemoryManager
- func (c *Controller) SaveTurn(ctx context.Context, sessionID string, msgs []*schema.Message) error
- type DocumentStore
- type Embedder
- type EmbeddingFunc
- type Indexer
- type LongTermStore
- type MessageRecord
- type Option
- type Retriever
- type ShortMemoryManager
- type Store
- type StoreEvent
- type StoreEventType
- type StoreHook
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EmbedderFunc ¶
func EmbedderFunc(e Embedder) gorm.EmbeddingFunc
Types ¶
type CompositeLongTermStore ¶ added in v1.1.0
type CompositeLongTermStore struct {
// contains filtered or unexported fields
}
CompositeLongTermStore 组合 Store + Retriever 实现 LongTermStore
func NewCompositeLongTermStore ¶ added in v1.1.0
func NewCompositeLongTermStore(store Store, retriever Retriever) *CompositeLongTermStore
NewCompositeLongTermStore 创建组合存储
func (*CompositeLongTermStore) AddHook ¶ added in v1.1.0
func (c *CompositeLongTermStore) AddHook(hook StoreHook)
AddHook 添加存储事件钩子 当 Store 发生 Save/Clear 操作时,通知 Retriever 更新索引
func (*CompositeLongTermStore) AttachIndexer ¶ added in v1.1.0
func (c *CompositeLongTermStore) AttachIndexer(indexer Indexer)
AttachIndexer 关联向量索引管理器
func (*CompositeLongTermStore) ClearSession ¶ added in v1.1.0
func (c *CompositeLongTermStore) ClearSession(ctx context.Context, sessionID string) error
func (*CompositeLongTermStore) Close ¶ added in v1.1.0
func (c *CompositeLongTermStore) Close() error
func (*CompositeLongTermStore) GetRetriever ¶ added in v1.1.0
func (c *CompositeLongTermStore) GetRetriever() Retriever
GetRetriever 获取底层 Retriever
func (*CompositeLongTermStore) GetSession ¶ added in v1.1.0
func (*CompositeLongTermStore) GetStore ¶ added in v1.1.0
func (c *CompositeLongTermStore) GetStore() Store
GetStore 获取底层 Store
func (*CompositeLongTermStore) IndexReady ¶ added in v1.1.0
func (c *CompositeLongTermStore) IndexReady() bool
IndexReady 返回向量索引是否就绪(无 indexer 时始终返回 true)
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller 记忆控制器,管理三类记忆
func NewController ¶
func NewController(systemPrompt []*schema.Message, shortMemory ShortMemoryManager, opts ...Option) *Controller
NewController 创建记忆控制器(保持向后兼容)
func (*Controller) AddSystemPrompt ¶ added in v1.1.0
func (c *Controller) AddSystemPrompt(msgs ...*schema.Message)
AddSystemPrompt 追加系统提示词
func (*Controller) BuildContext ¶
func (c *Controller) BuildContext(ctx context.Context, sessionID string, currentQuery string) ([]*schema.Message, error)
BuildContext 构建带记忆的上文
func (*Controller) Clear ¶
func (c *Controller) Clear(ctx context.Context, sessionID string) error
Clear 清空会话
func (*Controller) GetHistory ¶
GetHistory 获取完整历史
func (*Controller) GetShortMemory ¶ added in v1.1.0
func (c *Controller) GetShortMemory() ShortMemoryManager
GetShortMemory 获取短期记忆管理器
type DocumentStore ¶ added in v1.1.0
type DocumentStore interface {
// SaveDocuments 批量保存文档
SaveDocuments(ctx context.Context, collection string, docs []*schema.Document) error
// RecallDocuments 根据查询召回相关文档
RecallDocuments(ctx context.Context, collection string, query string, topK int) ([]*schema.Document, error)
// GetDocuments 获取集合中的所有文档
GetDocuments(ctx context.Context, collection string) ([]*schema.Document, error)
// DeleteCollection 删除整个集合
DeleteCollection(ctx context.Context, collection string) error
// Close 关闭存储
Close() error
}
DocumentStore 通用文档存储接口 用于非对话型 Agent 场景:用户画像 Agent、企业管理 Agent 等
type EmbeddingFunc ¶
EmbeddingFunc 文本转向量函数
type Indexer ¶ added in v1.1.0
type Indexer interface {
// AddToIndex 将消息的嵌入向量添加到索引
AddToIndex(ctx context.Context, sessionID string, msgs []*schema.Message) error
// RemoveFromIndex 从索引中移除指定会话的所有向量
RemoveFromIndex(sessionID string) error
// RebuildIndex 从存储中重建完整索引
RebuildIndex()
// IndexReady 返回索引是否就绪
IndexReady() bool
}
Indexer 向量索引管理接口 允许外部通知检索器更新索引(新增/删除向量、重建索引)
type LongTermStore ¶
LongTermStore 记忆存储接口(组合 Store + Retriever)
type MessageRecord ¶
type MessageRecord struct {
ID string `json:"id"`
SessionID string `json:"session_id"`
Role string `json:"role"`
Content string `json:"content"`
Embedding []float32 `json:"embedding,omitempty"`
Timestamp time.Time `json:"timestamp"`
Metadata map[string]string `json:"metadata,omitempty"`
}
MessageRecord 存储的记录结构
type Option ¶ added in v1.1.0
type Option func(*Controller)
Option Controller 配置选项
func WithLongStore ¶ added in v1.1.0
func WithLongStore(store LongTermStore) Option
WithLongStore 设置长期记忆存储器
type Retriever ¶ added in v1.1.0
type Retriever interface {
// Recall 根据查询召回相关消息
Recall(ctx context.Context, sessionID string, query string, topK int) ([]*schema.Message, error)
// Close 关闭检索器
Close() error
}
Retriever 消息检索接口 负责根据查询召回相关消息,不关心存储细节
type ShortMemoryManager ¶
type ShortMemoryManager interface {
// GetRecent 返回当前窗口内的完整消息(不进行压缩)
GetRecent(sessionID string) []*schema.Message
// GetContextMessages 返回构建上下文所需的短期记忆消息
// 内部可能整合:窗口内的完整消息 + 超出部分的摘要
GetContextMessages(sessionID string) []*schema.Message
// AddTurn 添加一轮对话,触发窗口维护、摘要生成等
AddTurn(sessionID string, msgs []*schema.Message)
// Clear 清空会话短期记忆
Clear(sessionID string)
}
ShortMemoryManager 短期记忆管理器
type Store ¶ added in v1.1.0
type Store interface {
// Save 保存消息
Save(ctx context.Context, sessionID string, msgs []*schema.Message) error
// GetSession 获取完整会话历史
GetSession(ctx context.Context, sessionID string) ([]*schema.Message, error)
// ClearSession 清空会话
ClearSession(ctx context.Context, sessionID string) error
// Close 关闭存储
Close() error
}
Store 纯消息存储接口 负责消息的持久化,不关心检索逻辑
type StoreEvent ¶ added in v1.1.0
type StoreEvent struct {
Type StoreEventType
SessionID string
Messages []*schema.Message // Save 事件时有值
}
StoreEvent 存储事件
type StoreEventType ¶ added in v1.1.0
type StoreEventType int
StoreEventType 存储事件类型
const ( StoreEventSave StoreEventType = iota // 新消息保存 StoreEventClear // 会话清空 )
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package embedder 提供文本转向量的实现 支持 OpenAI 兼容 API 和 Ollama 原生 API
|
Package embedder 提供文本转向量的实现 支持 OpenAI 兼容 API 和 Ollama 原生 API |
|
Package milvus 提供基于 Milvus 的消息检索
|
Package milvus 提供基于 Milvus 的消息检索 |
|
Package redis 提供基于 RediSearch 的消息检索 依赖 Redis Stack(>= 7.0)的 RediSearch 模块
|
Package redis 提供基于 RediSearch 的消息检索 依赖 Redis Stack(>= 7.0)的 RediSearch 模块 |