logic

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMemoryNotFound Memory 不存在
	ErrMemoryNotFound = &StoreError{Code: "MEMORY_NOT_FOUND", Message: "logic memory not found"}

	// ErrDuplicateKey 键冲突
	ErrDuplicateKey = &StoreError{Code: "DUPLICATE_KEY", Message: "logic memory with this key already exists"}

	// ErrInvalidNamespace 无效的 Namespace
	ErrInvalidNamespace = &StoreError{Code: "INVALID_NAMESPACE", Message: "invalid namespace"}

	// ErrStoreClosed 存储已关闭
	ErrStoreClosed = &StoreError{Code: "STORE_CLOSED", Message: "logic memory store is closed"}
)

错误定义

Functions

This section is empty.

Types

type ConsolidationConfig

type ConsolidationConfig struct {
	// SimilarityThreshold 相似度阈值(0.0-1.0)
	// 超过此阈值的 Memory 将被合并
	SimilarityThreshold float64

	// MinGroupSize 最小合并组大小
	// 只有当相似 Memory 数量 >= 此值时才进行合并
	MinGroupSize int

	// MaxMergeCount 单次合并的最大数量
	// 限制单次操作的 Memory 数量,避免长时间阻塞
	MaxMergeCount int

	// PreserveHighConfidence 保留高置信度的 Memory
	// 高置信度的 Memory 不会被合并到其他 Memory
	PreserveHighConfidenceThreshold float64

	// MergeStrategy 合并策略
	MergeStrategy MergeStrategy
}

ConsolidationConfig 合并配置

type ConsolidationEngine

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

ConsolidationEngine Memory 合并引擎 用于合并相似的 Memory,减少冗余,提高检索效率

func NewConsolidationEngine

func NewConsolidationEngine(store LogicMemoryStore, config *ConsolidationConfig) *ConsolidationEngine

NewConsolidationEngine 创建合并引擎

func (*ConsolidationEngine) Consolidate

func (e *ConsolidationEngine) Consolidate(ctx context.Context, namespace string) (*ConsolidationResult, error)

Consolidate 执行合并操作 返回合并的组数和删除的 Memory 数量

func (*ConsolidationEngine) SetSimilarityCalculator

func (e *ConsolidationEngine) SetSimilarityCalculator(calc SimilarityCalculator)

SetSimilarityCalculator 设置自定义相似度计算器

type ConsolidationResult

type ConsolidationResult struct {
	// TotalMemories 处理的 Memory 总数
	TotalMemories int

	// MergedGroups 合并的组数
	MergedGroups int

	// DeletedMemories 删除的 Memory 数量
	DeletedMemories int

	// MergedMemories 合并后的 Memory 列表
	MergedMemories []*LogicMemory

	// StartTime 开始时间
	StartTime time.Time

	// EndTime 结束时间
	EndTime time.Time
}

ConsolidationResult 合并结果

func (*ConsolidationResult) Duration

func (r *ConsolidationResult) Duration() time.Duration

Duration 返回执行时长

func (*ConsolidationResult) String

func (r *ConsolidationResult) String() string

String 返回结果摘要

type DefaultSimilarityCalculator

type DefaultSimilarityCalculator struct{}

DefaultSimilarityCalculator 默认相似度计算器 基于 Type、Key、Description 的简单相似度计算

func (*DefaultSimilarityCalculator) Calculate

func (c *DefaultSimilarityCalculator) Calculate(a, b *LogicMemory) float64

Calculate 计算相似度

type Event

type Event struct {
	// Type 事件类型(如 "user_message", "tool_result", "user_feedback" 等)
	Type string `json:"type"`

	// Source 来源(agent_id, user_id 等)
	Source string `json:"source"`

	// Data 事件数据(结构化)
	Data map[string]any `json:"data"`

	// Timestamp 时间戳
	Timestamp time.Time `json:"timestamp"`
}

Event 通用事件结构 用于 PatternMatcher 从事件中识别 Memory

type Filter

type Filter func(*FilterOptions)

Filter Logic Memory 查询过滤器

func WithMinConfidence

func WithMinConfidence(confidence float64) Filter

WithMinConfidence 按最低置信度过滤

func WithOrderBy

func WithOrderBy(orderBy OrderBy) Filter

WithOrderBy 指定排序方式

func WithScope

func WithScope(scope MemoryScope) Filter

WithScope 按作用域过滤

func WithTopK

func WithTopK(k int) Filter

WithTopK 限制返回数量

func WithType

func WithType(memoryType string) Filter

WithType 按类型过滤

type FilterOptions

type FilterOptions struct {
	// Type 过滤类型
	Type string

	// Scope 过滤作用域
	Scope MemoryScope

	// MinConfidence 最低置信度
	MinConfidence float64

	// MaxResults TopK 限制
	MaxResults int

	// OrderBy 排序字段
	OrderBy OrderBy

	// SinceLastAccess 最后访问时间过滤
	SinceLastAccess time.Duration
}

FilterOptions 过滤选项

func ApplyFilters

func ApplyFilters(filters ...Filter) *FilterOptions

ApplyFilters 应用过滤器到 FilterOptions

type InMemoryStore

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

InMemoryStore 内存存储实现(用于测试和简单场景)

func NewInMemoryStore

func NewInMemoryStore() *InMemoryStore

NewInMemoryStore 创建内存存储

func (*InMemoryStore) Close

func (s *InMemoryStore) Close() error

Close 关闭存储

func (*InMemoryStore) Delete

func (s *InMemoryStore) Delete(ctx context.Context, namespace, key string) error

Delete 删除 Memory

func (*InMemoryStore) Get

func (s *InMemoryStore) Get(ctx context.Context, namespace, key string) (*LogicMemory, error)

Get 获取单个 Memory

func (*InMemoryStore) GetStats

func (s *InMemoryStore) GetStats(ctx context.Context, namespace string) (*MemoryStats, error)

GetStats 获取统计信息

func (*InMemoryStore) GetTopK

func (s *InMemoryStore) GetTopK(ctx context.Context, namespace string, k int, orderBy OrderBy) ([]*LogicMemory, error)

GetTopK 获取 TopK Memory

func (*InMemoryStore) IncrementAccessCount

func (s *InMemoryStore) IncrementAccessCount(ctx context.Context, namespace, key string) error

IncrementAccessCount 增加访问计数

func (*InMemoryStore) List

func (s *InMemoryStore) List(ctx context.Context, namespace string, filters ...Filter) ([]*LogicMemory, error)

List 列出符合条件的 Memory

func (*InMemoryStore) Prune

func (s *InMemoryStore) Prune(ctx context.Context, criteria PruneCriteria) (int, error)

Prune 清理低价值 Memory

func (*InMemoryStore) Save

func (s *InMemoryStore) Save(ctx context.Context, memory *LogicMemory) error

Save 保存或更新 Memory

func (*InMemoryStore) SearchByScope

func (s *InMemoryStore) SearchByScope(ctx context.Context, namespace string, scope MemoryScope) ([]*LogicMemory, error)

SearchByScope 按作用域搜索

func (*InMemoryStore) SearchByType

func (s *InMemoryStore) SearchByType(ctx context.Context, namespace, memoryType string) ([]*LogicMemory, error)

SearchByType 按类型搜索

type LogicMemory

type LogicMemory struct {

	// ID 唯一标识符
	ID string `json:"id"`

	// Namespace 租户隔离(如 user:123, team:456, global)
	Namespace string `json:"namespace"`

	// Scope 作用域(Session/User/Global)
	Scope MemoryScope `json:"scope"`

	// Type Memory 类型(如 "user_preference", "behavior_pattern" 等)
	Type string `json:"type"`

	// Category 分类(可选,用于进一步分组)
	Category string `json:"category,omitempty"`

	// Key 唯一标识(如 "writing_tone_preference")
	// Namespace + Key 构成全局唯一键
	Key string `json:"key"`

	// Value 值(结构化数据)
	// 应用层可以存储任意 JSON 可序列化的数据
	Value any `json:"value"`

	// Description 人类可读描述(用于 Prompt 注入)
	// 例如:"用户偏好口语化表达,避免使用书面语"
	Description string `json:"description"`

	// Provenance 记忆溯源信息
	Provenance *memory.MemoryProvenance `json:"provenance"`

	// AccessCount 访问次数(用于 LRU 淘汰)
	AccessCount int `json:"access_count"`

	// LastAccessed 最后访问时间
	LastAccessed time.Time `json:"last_accessed"`

	// Metadata 扩展字段(应用层自定义)
	Metadata map[string]any `json:"metadata,omitempty"`

	// CreatedAt 创建时间
	CreatedAt time.Time `json:"created_at"`

	// UpdatedAt 更新时间
	UpdatedAt time.Time `json:"updated_at"`
}

LogicMemory 逻辑记忆(通用结构) Logic Memory 用于存储用户偏好、行为模式等可学习的记忆

type LogicMemoryStore

type LogicMemoryStore interface {

	// Save 保存或更新 Memory
	// 如果 Namespace + Key 已存在,则更新;否则创建新记录
	Save(ctx context.Context, memory *LogicMemory) error

	// Get 获取单个 Memory
	// 返回 ErrMemoryNotFound 如果不存在
	Get(ctx context.Context, namespace, key string) (*LogicMemory, error)

	// Delete 删除 Memory
	// 如果不存在不返回错误
	Delete(ctx context.Context, namespace, key string) error

	// List 列出符合条件的 Memory
	// filters 用于过滤和排序
	List(ctx context.Context, namespace string, filters ...Filter) ([]*LogicMemory, error)

	// SearchByType 按类型搜索
	SearchByType(ctx context.Context, namespace, memoryType string) ([]*LogicMemory, error)

	// SearchByScope 按作用域搜索
	SearchByScope(ctx context.Context, namespace string, scope MemoryScope) ([]*LogicMemory, error)

	// GetTopK 获取 TopK Memory
	// 按 orderBy 排序后返回前 k 个
	GetTopK(ctx context.Context, namespace string, k int, orderBy OrderBy) ([]*LogicMemory, error)

	// IncrementAccessCount 增加访问计数
	// 同时更新 LastAccessed 时间
	IncrementAccessCount(ctx context.Context, namespace, key string) error

	// GetStats 获取统计信息
	GetStats(ctx context.Context, namespace string) (*MemoryStats, error)

	// Prune 清理低价值 Memory
	// 返回清理的数量
	Prune(ctx context.Context, criteria PruneCriteria) (int, error)

	// Close 关闭连接
	Close() error
}

LogicMemoryStore 存储接口(类似现有 BackendProtocol) 应用层可以提供不同的实现(PostgreSQL, Redis, InMemory 等)

type Manager

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

Manager Logic Memory 核心管理器 负责 Memory 的捕获、存储、检索、合并和清理

func NewManager

func NewManager(config *ManagerConfig) (*Manager, error)

NewManager 创建 Logic Memory Manager

func (*Manager) Close

func (m *Manager) Close() error

Close 关闭 Manager

func (*Manager) DeleteMemory

func (m *Manager) DeleteMemory(ctx context.Context, namespace, key string) error

DeleteMemory 删除 Memory

func (*Manager) GetMemory

func (m *Manager) GetMemory(ctx context.Context, namespace, key string) (*LogicMemory, error)

GetMemory 获取单个 Memory

func (*Manager) GetStats

func (m *Manager) GetStats(ctx context.Context, namespace string) (*MemoryStats, error)

GetStats 获取统计信息

func (*Manager) ProcessEvent

func (m *Manager) ProcessEvent(ctx context.Context, event Event) error

ProcessEvent 处理事件,自动识别和记录 Memory(被动触发) 这是核心的自动捕获逻辑

func (*Manager) PruneMemories

func (m *Manager) PruneMemories(ctx context.Context, criteria PruneCriteria) (int, error)

PruneMemories 清理低价值 Memory(定期任务)

func (*Manager) RecordMemory

func (m *Manager) RecordMemory(ctx context.Context, memory *LogicMemory) error

RecordMemory 主动记录 Memory(应用层手动调用)

func (*Manager) RetrieveMemories

func (m *Manager) RetrieveMemories(
	ctx context.Context,
	namespace string,
	filters ...Filter,
) ([]*LogicMemory, error)

RetrieveMemories 检索 Memory(用于 Prompt 注入)

type ManagerConfig

type ManagerConfig struct {
	// Store 存储后端(必需)
	Store LogicMemoryStore

	// Matchers 模式匹配器列表(可选,至少提供一个才能自动捕获)
	Matchers []PatternMatcher

	// DefaultProvenance 默认溯源信息(可选)
	DefaultProvenance *memory.MemoryProvenance

	// AutoConsolidate 是否自动合并相似 Memory(默认 false)
	AutoConsolidate bool

	// ConsolidationThreshold 相似度阈值(用于自动合并,默认 0.85)
	ConsolidationThreshold float64

	// ConfidenceBoost 每次重复出现的置信度提升(默认 0.05)
	ConfidenceBoost float64
}

ManagerConfig Manager 配置

type MemoryScope

type MemoryScope string

MemoryScope 记忆作用域

const (
	// ScopeSession 单次会话级别(短期)
	ScopeSession MemoryScope = "session"
	// ScopeUser 用户级别(中期)
	ScopeUser MemoryScope = "user"
	// ScopeGlobal 全局级别(长期)
	ScopeGlobal MemoryScope = "global"
)

type MemoryStats

type MemoryStats struct {
	// TotalCount 总记忆数
	TotalCount int

	// CountByType 按类型统计
	CountByType map[string]int

	// CountByScope 按作用域统计
	CountByScope map[MemoryScope]int

	// AverageConfidence 平均置信度
	AverageConfidence float64

	// LastUpdated 最后更新时间
	LastUpdated time.Time
}

MemoryStats Logic Memory 统计信息

type MergeStrategy

type MergeStrategy string

MergeStrategy 合并策略

const (
	// MergeStrategyKeepNewest 保留最新的 Memory
	MergeStrategyKeepNewest MergeStrategy = "keep_newest"

	// MergeStrategyKeepHighestConfidence 保留置信度最高的 Memory
	MergeStrategyKeepHighestConfidence MergeStrategy = "keep_highest_confidence"

	// MergeStrategyMergeDescriptions 合并描述
	MergeStrategyMergeDescriptions MergeStrategy = "merge_descriptions"
)

type Metrics

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

Metrics Logic Memory 指标收集器 提供可观测性支持,可以对接 Prometheus 或其他监控系统

func NewMetrics

func NewMetrics() *Metrics

NewMetrics 创建指标收集器

func (*Metrics) ExportToPrometheus

func (m *Metrics) ExportToPrometheus(exporter PrometheusExporter)

ExportToPrometheus 导出指标到 Prometheus

func (*Metrics) GetSnapshot

func (m *Metrics) GetSnapshot() *MetricsSnapshot

GetSnapshot 获取指标快照

func (*Metrics) RecordConsolidation

func (m *Metrics) RecordConsolidation(mergedGroups, deletedMemories int)

RecordConsolidation 记录合并操作

func (*Metrics) RecordDelete

func (m *Metrics) RecordDelete(namespace string)

RecordDelete 记录删除操作

func (*Metrics) RecordEventProcess

func (m *Metrics) RecordEventProcess(eventType string, duration time.Duration, err error)

RecordEventProcess 记录事件处理

func (*Metrics) RecordGet

func (m *Metrics) RecordGet(duration time.Duration, err error)

RecordGet 记录获取操作

func (*Metrics) RecordPrune

func (m *Metrics) RecordPrune(deletedCount int)

RecordPrune 记录清理操作

func (*Metrics) RecordSave

func (m *Metrics) RecordSave(namespace, memoryType string, scope MemoryScope, duration time.Duration, err error)

RecordSave 记录保存操作

func (*Metrics) Reset

func (m *Metrics) Reset()

Reset 重置指标

type MetricsSnapshot

type MetricsSnapshot struct {
	Timestamp time.Time

	// 计数器
	MemorySaveTotal    int64
	MemorySaveErrors   int64
	MemoryGetTotal     int64
	MemoryGetErrors    int64
	MemoryDeleteTotal  int64
	EventProcessTotal  int64
	EventProcessErrors int64
	ConsolidationTotal int64
	PruneTotal         int64

	// 分布
	MemoryByNamespace map[string]int64
	MemoryByType      map[string]int64
	MemoryByScope     map[MemoryScope]int64

	// 耗时统计
	AvgSaveDuration         time.Duration
	AvgGetDuration          time.Duration
	AvgEventProcessDuration time.Duration
	P99SaveDuration         time.Duration
	P99GetDuration          time.Duration
	P99EventProcessDuration time.Duration
}

MetricsSnapshot 指标快照

func (*MetricsSnapshot) EventProcessErrorRate

func (s *MetricsSnapshot) EventProcessErrorRate() float64

EventProcessErrorRate 返回事件处理错误率

func (*MetricsSnapshot) GetErrorRate

func (s *MetricsSnapshot) GetErrorRate() float64

GetErrorRate 返回获取错误率

func (*MetricsSnapshot) SaveErrorRate

func (s *MetricsSnapshot) SaveErrorRate() float64

SaveErrorRate 返回保存错误率

func (*MetricsSnapshot) TotalMemories

func (s *MetricsSnapshot) TotalMemories() int64

TotalMemories 返回总 Memory 数量

type MySQLStore

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

MySQLStore MySQL 存储实现

func NewMySQLStore

func NewMySQLStore(config *MySQLStoreConfig) (*MySQLStore, error)

NewMySQLStore 创建 MySQL 存储

func (*MySQLStore) Close

func (s *MySQLStore) Close() error

Close 关闭存储

func (*MySQLStore) Delete

func (s *MySQLStore) Delete(ctx context.Context, namespace, key string) error

Delete 删除 Memory

func (*MySQLStore) Get

func (s *MySQLStore) Get(ctx context.Context, namespace, key string) (*LogicMemory, error)

Get 获取单个 Memory

func (*MySQLStore) GetStats

func (s *MySQLStore) GetStats(ctx context.Context, namespace string) (*MemoryStats, error)

GetStats 获取统计信息

func (*MySQLStore) GetTopK

func (s *MySQLStore) GetTopK(ctx context.Context, namespace string, k int, orderBy OrderBy) ([]*LogicMemory, error)

GetTopK 获取 TopK Memory

func (*MySQLStore) IncrementAccessCount

func (s *MySQLStore) IncrementAccessCount(ctx context.Context, namespace, key string) error

IncrementAccessCount 增加访问计数

func (*MySQLStore) List

func (s *MySQLStore) List(ctx context.Context, namespace string, filters ...Filter) ([]*LogicMemory, error)

List 列出符合条件的 Memory

func (*MySQLStore) Prune

func (s *MySQLStore) Prune(ctx context.Context, criteria PruneCriteria) (int, error)

Prune 清理低价值 Memory

func (*MySQLStore) Save

func (s *MySQLStore) Save(ctx context.Context, mem *LogicMemory) error

Save 保存或更新 Memory

func (*MySQLStore) SearchByScope

func (s *MySQLStore) SearchByScope(ctx context.Context, namespace string, scope MemoryScope) ([]*LogicMemory, error)

SearchByScope 按作用域搜索

func (*MySQLStore) SearchByType

func (s *MySQLStore) SearchByType(ctx context.Context, namespace, memoryType string) ([]*LogicMemory, error)

SearchByType 按类型搜索

type MySQLStoreConfig

type MySQLStoreConfig struct {
	// DB 数据库连接(必需)
	DB *sql.DB

	// TableName 表名(默认 "logic_memories")
	TableName string

	// AutoMigrate 是否自动创建表(默认 true)
	AutoMigrate bool
}

MySQLStoreConfig MySQL 存储配置

type NoopMatcher

type NoopMatcher struct{}

NoopMatcher 空实现(用于测试或默认场景)

func (*NoopMatcher) MatchEvent

func (m *NoopMatcher) MatchEvent(ctx context.Context, event Event) ([]*LogicMemory, error)

MatchEvent 实现 PatternMatcher 接口

func (*NoopMatcher) SupportedEventTypes

func (m *NoopMatcher) SupportedEventTypes() []string

SupportedEventTypes 实现 PatternMatcher 接口

type OrderBy

type OrderBy string

OrderBy 排序方式

const (
	// OrderByConfidence 按置信度降序
	OrderByConfidence OrderBy = "confidence DESC"
	// OrderByLastAccessed 按最后访问时间降序
	OrderByLastAccessed OrderBy = "last_accessed DESC"
	// OrderByCreatedAt 按创建时间降序
	OrderByCreatedAt OrderBy = "created_at DESC"
	// OrderByAccessCount 按访问次数降序
	OrderByAccessCount OrderBy = "access_count DESC"
)

type PatternMatcher

type PatternMatcher interface {
	// MatchEvent 从事件中识别 Memory
	// 返回识别出的 Memory 列表(可能为空)
	MatchEvent(ctx context.Context, event Event) ([]*LogicMemory, error)

	// SupportedEventTypes 返回支持的事件类型列表
	// 用于 Manager 筛选事件,避免不必要的调用
	SupportedEventTypes() []string
}

PatternMatcher 模式识别接口(应用层实现) 用于从事件中识别和提取 Logic Memory

type PostgreSQLStore

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

PostgreSQLStore PostgreSQL 存储实现

func NewPostgreSQLStore

func NewPostgreSQLStore(config *PostgreSQLStoreConfig) (*PostgreSQLStore, error)

NewPostgreSQLStore 创建 PostgreSQL 存储

func (*PostgreSQLStore) Close

func (s *PostgreSQLStore) Close() error

Close 关闭存储

func (*PostgreSQLStore) Delete

func (s *PostgreSQLStore) Delete(ctx context.Context, namespace, key string) error

Delete 删除 Memory

func (*PostgreSQLStore) Get

func (s *PostgreSQLStore) Get(ctx context.Context, namespace, key string) (*LogicMemory, error)

Get 获取单个 Memory

func (*PostgreSQLStore) GetStats

func (s *PostgreSQLStore) GetStats(ctx context.Context, namespace string) (*MemoryStats, error)

GetStats 获取统计信息

func (*PostgreSQLStore) GetTopK

func (s *PostgreSQLStore) GetTopK(ctx context.Context, namespace string, k int, orderBy OrderBy) ([]*LogicMemory, error)

GetTopK 获取 TopK Memory

func (*PostgreSQLStore) IncrementAccessCount

func (s *PostgreSQLStore) IncrementAccessCount(ctx context.Context, namespace, key string) error

IncrementAccessCount 增加访问计数

func (*PostgreSQLStore) List

func (s *PostgreSQLStore) List(ctx context.Context, namespace string, filters ...Filter) ([]*LogicMemory, error)

List 列出符合条件的 Memory

func (*PostgreSQLStore) Prune

func (s *PostgreSQLStore) Prune(ctx context.Context, criteria PruneCriteria) (int, error)

Prune 清理低价值 Memory

func (*PostgreSQLStore) Save

func (s *PostgreSQLStore) Save(ctx context.Context, mem *LogicMemory) error

Save 保存或更新 Memory

func (*PostgreSQLStore) SearchByScope

func (s *PostgreSQLStore) SearchByScope(ctx context.Context, namespace string, scope MemoryScope) ([]*LogicMemory, error)

SearchByScope 按作用域搜索

func (*PostgreSQLStore) SearchByType

func (s *PostgreSQLStore) SearchByType(ctx context.Context, namespace, memoryType string) ([]*LogicMemory, error)

SearchByType 按类型搜索

type PostgreSQLStoreConfig

type PostgreSQLStoreConfig struct {
	// DB 数据库连接(必需)
	DB *sql.DB

	// TableName 表名(默认 "logic_memories")
	TableName string

	// AutoMigrate 是否自动创建表(默认 true)
	AutoMigrate bool
}

PostgreSQLStoreConfig PostgreSQL 存储配置

type PrometheusExporter

type PrometheusExporter interface {
	// ExportGauge 导出 Gauge 指标
	ExportGauge(name string, value float64, labels map[string]string)

	// ExportCounter 导出 Counter 指标
	ExportCounter(name string, value float64, labels map[string]string)

	// ExportHistogram 导出 Histogram 指标
	ExportHistogram(name string, value float64, labels map[string]string)
}

PrometheusExporter Prometheus 导出器接口 应用层可以实现此接口将指标导出到 Prometheus

type PruneCriteria

type PruneCriteria struct {
	// MinConfidence 最低置信度(低于此值将被清理)
	MinConfidence float64

	// MaxAge 最大年龄(超过此时长将被清理)
	MaxAge time.Duration

	// MinAccessCount 最少访问次数(低于此值将被清理)
	MinAccessCount int

	// SinceLastAccess 最后访问时间(超过此时长未访问将被清理)
	SinceLastAccess time.Duration
}

PruneCriteria 清理条件

type SimilarityCalculator

type SimilarityCalculator interface {
	// Calculate 计算两个 Memory 的相似度(0.0-1.0)
	Calculate(a, b *LogicMemory) float64
}

SimilarityCalculator 相似度计算接口

type StoreConfig

type StoreConfig struct {
	// Type 存储类型("postgres", "redis", "inmemory")
	Type string

	// ConnectionString 连接字符串(PostgreSQL/Redis)
	ConnectionString string

	// TableName 表名(PostgreSQL,可选,默认 "logic_memories")
	TableName string

	// KeyPrefix 键前缀(Redis,可选)
	KeyPrefix string

	// MaxConnections 最大连接数(可选)
	MaxConnections int
}

StoreConfig 存储配置(通用)

type StoreError

type StoreError struct {
	Code    string
	Message string
	Err     error
}

StoreError 存储错误

func NewStoreError

func NewStoreError(code, message string, err error) *StoreError

NewStoreError 创建新的存储错误

func (*StoreError) Error

func (e *StoreError) Error() string

func (*StoreError) Unwrap

func (e *StoreError) Unwrap() error

Jump to

Keyboard shortcuts

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