Documentation
¶
Index ¶
- Constants
- type ConversationMessageModel
- type MemoryStore
- func (m *MemoryStore) AutoMigrate() error
- func (m *MemoryStore) CleanupMessagesByLimit(ctx context.Context, userID, sessionID string, keepLimit int) error
- func (m *MemoryStore) CleanupOldMessages(ctx context.Context, userID string, before time.Time) error
- func (m *MemoryStore) ClearUserMemories(ctx context.Context, userID string) error
- func (m *MemoryStore) Close() error
- func (m *MemoryStore) DeleteMessages(ctx context.Context, sessionID string, userID string) error
- func (m *MemoryStore) DeleteSessionSummary(ctx context.Context, sessionID string, userID string) error
- func (m *MemoryStore) DeleteUserMemoriesByIds(ctx context.Context, userID string, memoryIDs []string) error
- func (m *MemoryStore) DeleteUserMemory(ctx context.Context, memoryID string) error
- func (m *MemoryStore) GetMessageCount(ctx context.Context, userID, sessionID string) (int, error)
- func (m *MemoryStore) GetMessages(ctx context.Context, sessionID string, userID string, limit int) ([]*memory.ConversationMessage, error)
- func (m *MemoryStore) GetSessionSummary(ctx context.Context, sessionID string, userID string) (*memory.SessionSummary, error)
- func (m *MemoryStore) GetUserMemories(ctx context.Context, userID string, limit int, ...) ([]*memory.UserMemory, error)
- func (m *MemoryStore) Health(ctx context.Context) error
- func (m *MemoryStore) SaveMessage(ctx context.Context, message *memory.ConversationMessage) error
- func (m *MemoryStore) SaveSessionSummary(ctx context.Context, summary *memory.SessionSummary) error
- func (m *MemoryStore) SaveUserMemory(ctx context.Context, userMemory *memory.UserMemory) error
- func (m *MemoryStore) SearchUserMemories(ctx context.Context, userID string, query string, limit int) ([]*memory.UserMemory, error)
- func (m *MemoryStore) SetTablePrefix(prefix string)
- func (m *MemoryStore) UpdateSessionSummary(ctx context.Context, summary *memory.SessionSummary) error
- func (m *MemoryStore) UpdateUserMemory(ctx context.Context, memory *memory.UserMemory) error
- type MessageParts
- type SQLStore
- func (s *SQLStore) AutoMigrate() error
- func (s *SQLStore) CleanupMessagesByLimit(ctx context.Context, userID, sessionID string, keepLimit int) error
- func (s *SQLStore) CleanupOldMessages(ctx context.Context, userID string, before time.Time) error
- func (s *SQLStore) ClearUserMemories(ctx context.Context, userID string) error
- func (s *SQLStore) Close() error
- func (s *SQLStore) DeleteMessages(ctx context.Context, sessionID string, userID string) error
- func (s *SQLStore) DeleteSessionSummary(ctx context.Context, sessionID string, userID string) error
- func (s *SQLStore) DeleteUserMemoriesByIds(ctx context.Context, userID string, memoryIDs []string) error
- func (s *SQLStore) DeleteUserMemory(ctx context.Context, memoryID string) error
- func (s *SQLStore) GetMessageCount(ctx context.Context, userID, sessionID string) (int, error)
- func (s *SQLStore) GetMessages(ctx context.Context, sessionID string, userID string, limit int) ([]*memory.ConversationMessage, error)
- func (s *SQLStore) GetSessionSummary(ctx context.Context, sessionID string, userID string) (*memory.SessionSummary, error)
- func (s *SQLStore) GetUserMemories(ctx context.Context, userID string, limit int, ...) ([]*memory.UserMemory, error)
- func (s *SQLStore) Health(ctx context.Context) error
- func (s *SQLStore) SaveMessage(ctx context.Context, message *memory.ConversationMessage) error
- func (s *SQLStore) SaveSessionSummary(ctx context.Context, summary *memory.SessionSummary) error
- func (s *SQLStore) SaveUserMemory(ctx context.Context, memory *memory.UserMemory) error
- func (s *SQLStore) SearchUserMemories(ctx context.Context, userID string, query string, limit int) ([]*memory.UserMemory, error)
- func (s *SQLStore) SetTablePrefix(prefix string)
- func (s *SQLStore) UpdateSessionSummary(ctx context.Context, summary *memory.SessionSummary) error
- func (s *SQLStore) UpdateUserMemory(ctx context.Context, userMemory *memory.UserMemory) error
- type SessionSummaryModel
- type TableNameProvider
- type UserMemoryModel
Constants ¶
const ( // DialectMySQL MySQL方言 DialectMySQL string = "mysql" // DialectPostgreSQL PostgreSQL方言 DialectPostgreSQL string = "postgres" // DialectSQLite SQLite方言 DialectSQLite string = "sqlite" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConversationMessageModel ¶
type ConversationMessageModel struct {
ID string `gorm:"primaryKey;size:255" json:"id"`
SessionID string `gorm:"index;size:255;not null" json:"sessionId"`
UserID string `gorm:"index;size:255;not null" json:"userId"`
Role string `gorm:"size:50;not null" json:"role"`
// 保留Content字段用于向后兼容
Content string `gorm:"type:text" json:"content,omitempty"`
// 多部分内容,使用自定义类型直接存储
Parts MessageParts `gorm:"type:text" json:"parts,omitempty"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"createdAt"`
}
ConversationMessageModel GORM模型 - 对话消息表
func (*ConversationMessageModel) FromConversationMessage ¶
func (m *ConversationMessageModel) FromConversationMessage(message *memory.ConversationMessage)
FromConversationMessage 将业务模型转换为数据库模型
func (*ConversationMessageModel) ToConversationMessage ¶
func (m *ConversationMessageModel) ToConversationMessage() *memory.ConversationMessage
ToConversationMessage 将数据库模型转换为业务模型
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore 内存存储实现 这是一个基于内存的记忆存储实现,适合测试和开发环境
func (*MemoryStore) AutoMigrate ¶
func (m *MemoryStore) AutoMigrate() error
func (*MemoryStore) CleanupMessagesByLimit ¶ added in v0.0.10
func (m *MemoryStore) CleanupMessagesByLimit(ctx context.Context, userID, sessionID string, keepLimit int) error
CleanupMessagesByLimit 按数量限制清理消息,保留最新的N条
func (*MemoryStore) CleanupOldMessages ¶ added in v0.0.10
func (m *MemoryStore) CleanupOldMessages(ctx context.Context, userID string, before time.Time) error
CleanupOldMessages 清理指定时间之前的消息
func (*MemoryStore) ClearUserMemories ¶
func (m *MemoryStore) ClearUserMemories(ctx context.Context, userID string) error
ClearUserMemories 清空用户的所有记忆
func (*MemoryStore) DeleteMessages ¶
DeleteMessages 删除会话的消息历史
func (*MemoryStore) DeleteSessionSummary ¶
func (m *MemoryStore) DeleteSessionSummary(ctx context.Context, sessionID string, userID string) error
DeleteSessionSummary 删除会话摘要
func (*MemoryStore) DeleteUserMemoriesByIds ¶
func (*MemoryStore) DeleteUserMemory ¶
func (m *MemoryStore) DeleteUserMemory(ctx context.Context, memoryID string) error
DeleteUserMemory 删除用户记忆
func (*MemoryStore) GetMessageCount ¶ added in v0.0.10
GetMessageCount 获取消息总数
func (*MemoryStore) GetMessages ¶
func (m *MemoryStore) GetMessages(ctx context.Context, sessionID string, userID string, limit int) ([]*memory.ConversationMessage, error)
GetMessages 获取会话的消息历史
func (*MemoryStore) GetSessionSummary ¶
func (m *MemoryStore) GetSessionSummary(ctx context.Context, sessionID string, userID string) (*memory.SessionSummary, error)
GetSessionSummary 获取会话摘要
func (*MemoryStore) GetUserMemories ¶
func (m *MemoryStore) GetUserMemories(ctx context.Context, userID string, limit int, retrieval memory.MemoryRetrieval) ([]*memory.UserMemory, error)
GetUserMemories 获取用户的记忆列表
func (*MemoryStore) Health ¶
func (m *MemoryStore) Health(ctx context.Context) error
Health 检查存储健康状态
func (*MemoryStore) SaveMessage ¶
func (m *MemoryStore) SaveMessage(ctx context.Context, message *memory.ConversationMessage) error
SaveMessage 保存对话消息
func (*MemoryStore) SaveSessionSummary ¶
func (m *MemoryStore) SaveSessionSummary(ctx context.Context, summary *memory.SessionSummary) error
SaveSessionSummary 保存会话摘要
func (*MemoryStore) SaveUserMemory ¶
func (m *MemoryStore) SaveUserMemory(ctx context.Context, userMemory *memory.UserMemory) error
SaveUserMemory 保存用户记忆
func (*MemoryStore) SearchUserMemories ¶
func (m *MemoryStore) SearchUserMemories(ctx context.Context, userID string, query string, limit int) ([]*memory.UserMemory, error)
SearchUserMemories 搜索用户记忆(简单的文本匹配实现)
func (*MemoryStore) SetTablePrefix ¶
func (m *MemoryStore) SetTablePrefix(prefix string)
func (*MemoryStore) UpdateSessionSummary ¶
func (m *MemoryStore) UpdateSessionSummary(ctx context.Context, summary *memory.SessionSummary) error
UpdateSessionSummary 更新会话摘要
func (*MemoryStore) UpdateUserMemory ¶
func (m *MemoryStore) UpdateUserMemory(ctx context.Context, memory *memory.UserMemory) error
UpdateUserMemory 更新用户记忆
type MessageParts ¶ added in v0.0.10
type MessageParts []schema.MessageInputPart
MessageParts 自定义 GORM 类型,用于处理 []schema.MessageInputPart 的序列化
func (MessageParts) GormDataType ¶ added in v0.0.10
func (mp MessageParts) GormDataType() string
GormValue 为 GORM 提供特定的数据类型支持
func (*MessageParts) Scan ¶ added in v0.0.10
func (mp *MessageParts) Scan(value interface{}) error
Scan 实现 sql.Scanner 接口,用于从数据库读取数据
type SQLStore ¶
type SQLStore struct {
// contains filtered or unexported fields
}
SQLStore 通用SQL存储实现 支持MySQL、PostgreSQL和SQLite
func NewGormStorage ¶
NewGormStorage 创建新的SQL存储实例
func (*SQLStore) CleanupMessagesByLimit ¶ added in v0.0.10
func (s *SQLStore) CleanupMessagesByLimit(ctx context.Context, userID, sessionID string, keepLimit int) error
CleanupMessagesByLimit 按数量限制清理消息,保留最新的N条
func (*SQLStore) CleanupOldMessages ¶ added in v0.0.10
CleanupOldMessages 清理指定时间之前的消息
func (*SQLStore) ClearUserMemories ¶
ClearUserMemories 清空用户的所有记忆
func (*SQLStore) DeleteMessages ¶
DeleteMessages 删除会话的消息历史
func (*SQLStore) DeleteSessionSummary ¶
DeleteSessionSummary 删除会话摘要
func (*SQLStore) DeleteUserMemoriesByIds ¶
func (*SQLStore) DeleteUserMemory ¶
DeleteUserMemory 删除用户记忆
func (*SQLStore) GetMessageCount ¶ added in v0.0.10
GetMessageCount 获取消息总数
func (*SQLStore) GetMessages ¶
func (s *SQLStore) GetMessages(ctx context.Context, sessionID string, userID string, limit int) ([]*memory.ConversationMessage, error)
GetMessages 获取会话的消息历史
func (*SQLStore) GetSessionSummary ¶
func (s *SQLStore) GetSessionSummary(ctx context.Context, sessionID string, userID string) (*memory.SessionSummary, error)
GetSessionSummary 获取会话摘要
func (*SQLStore) GetUserMemories ¶
func (s *SQLStore) GetUserMemories(ctx context.Context, userID string, limit int, retrieval memory.MemoryRetrieval) ([]*memory.UserMemory, error)
GetUserMemories 获取用户的记忆列表
func (*SQLStore) SaveMessage ¶
SaveMessage 保存对话消息
func (*SQLStore) SaveSessionSummary ¶
SaveSessionSummary 保存会话摘要
func (*SQLStore) SaveUserMemory ¶
SaveUserMemory 保存用户记忆
func (*SQLStore) SearchUserMemories ¶
func (s *SQLStore) SearchUserMemories(ctx context.Context, userID string, query string, limit int) ([]*memory.UserMemory, error)
SearchUserMemories 搜索用户记忆(基于内容关键词搜索)
func (*SQLStore) SetTablePrefix ¶
func (*SQLStore) UpdateSessionSummary ¶
UpdateSessionSummary 更新会话摘要
func (*SQLStore) UpdateUserMemory ¶
UpdateUserMemory 更新用户记忆
type SessionSummaryModel ¶
type SessionSummaryModel struct {
SessionID string `gorm:"primaryKey;size:255" json:"sessionId"`
UserID string `gorm:"primaryKey;size:255" json:"userId"`
Summary string `gorm:"type:text;not null" json:"summary"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"createdAt"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updatedAt"`
}
SessionSummaryModel GORM模型 - 会话摘要表
func (*SessionSummaryModel) FromSessionSummary ¶
func (m *SessionSummaryModel) FromSessionSummary(sessionSummary *memory.SessionSummary)
FromSessionSummary 将业务模型转换为数据库模型
func (*SessionSummaryModel) ToSessionSummary ¶
func (m *SessionSummaryModel) ToSessionSummary() *memory.SessionSummary
ToSessionSummary 将数据库模型转换为业务模型
type TableNameProvider ¶
type TableNameProvider struct {
// contains filtered or unexported fields
}
TableNameProvider provides table names with configurable prefix
func NewTableNameProvider ¶
func NewTableNameProvider(prefix string) *TableNameProvider
NewTableNameProvider creates a new table name provider with the given prefix
func (*TableNameProvider) GetConversationMessageTableName ¶
func (p *TableNameProvider) GetConversationMessageTableName() string
GetConversationMessageTableName returns the table name for conversation messages
func (*TableNameProvider) GetSessionSummaryTableName ¶
func (p *TableNameProvider) GetSessionSummaryTableName() string
GetSessionSummaryTableName returns the table name for session summaries
func (*TableNameProvider) GetUserMemoryTableName ¶
func (p *TableNameProvider) GetUserMemoryTableName() string
GetUserMemoryTableName returns the table name for user memories
type UserMemoryModel ¶
type UserMemoryModel struct {
ID string `gorm:"primaryKey;size:255" json:"id"`
UserID string `gorm:"index;size:255;not null" json:"userId"`
Memory string `gorm:"type:text;not null" json:"memory"`
Input string `gorm:"type:text" json:"input"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"createdAt"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updatedAt"`
}
UserMemoryModel GORM模型 - 用户记忆表
func (*UserMemoryModel) FromUserMemory ¶
func (m *UserMemoryModel) FromUserMemory(userMemory *memory.UserMemory)
FromUserMemory 将业务模型转换为数据库模型
func (*UserMemoryModel) ToUserMemory ¶
func (m *UserMemoryModel) ToUserMemory() *memory.UserMemory
ToUserMemory 将数据库模型转换为业务模型