Documentation
¶
Index ¶
- Constants
- Variables
- func DedupUserKnowledge(ctx context.Context, db *sql.DB, userID string) (int, error)
- func IngestGetCursor(ctx context.Context, db *sql.DB, sessionID string) (int64, error)
- func IngestIncStat(ctx context.Context, db *sql.DB, sessionID, ruleName string) error
- func IngestSetCursor(ctx context.Context, db *sql.DB, sessionID string, lastMessageID int64) error
- func MarkPhase2Cooldown(ctx context.Context, db *sql.DB, holder string, cooldown time.Duration) error
- func MigrateLegacySessionKnowledge(ctx context.Context, db *sql.DB) (int, error)
- func PruneUnused(ctx context.Context, db *sql.DB, maxUnusedDays int) error
- func ReleasePhase2(ctx context.Context, db *sql.DB, holder string) error
- func TryClaimPhase2(ctx context.Context, db *sql.DB, holder string, lease, cooldown time.Duration) (bool, error)
- type IndexNode
- type IndexSearchResult
- type IndexTree
- type KnowledgeEntry
- type MemoryItem
- type PageIndexDoc
- type PageIndexHit
- type PageIndexKind
- type PageIndexSearchOptions
- type Preference
- type Priority
- type SQLiteIndexStore
- func (s *SQLiteIndexStore) AddNode(ctx context.Context, userID, sourceID string, node *IndexNode, parentID string) error
- func (s *SQLiteIndexStore) CreateIndex(ctx context.Context, userID, sourceID, title string, nodes []*IndexNode) (*IndexTree, error)
- func (s *SQLiteIndexStore) DeleteIndex(ctx context.Context, userID, sourceID string) error
- func (s *SQLiteIndexStore) GetAllIndexes(ctx context.Context, userID string) ([]*IndexTree, error)
- func (s *SQLiteIndexStore) GetIndex(ctx context.Context, userID, sourceID string) (*IndexTree, error)
- func (s *SQLiteIndexStore) RemoveNode(ctx context.Context, userID, sourceID, nodeID string) error
- func (s *SQLiteIndexStore) SearchIndex(ctx context.Context, userID, query string, limit int) (*IndexSearchResult, error)
- func (s *SQLiteIndexStore) UpdateIndex(ctx context.Context, tree *IndexTree) error
- func (s *SQLiteIndexStore) UpdateNode(ctx context.Context, userID, sourceID string, node *IndexNode) error
- type SQLiteKnowledgeStore
- func (s *SQLiteKnowledgeStore) Add(ctx context.Context, entry KnowledgeEntry) error
- func (s *SQLiteKnowledgeStore) Clear(ctx context.Context, userID string) error
- func (s *SQLiteKnowledgeStore) DB() *sql.DB
- func (s *SQLiteKnowledgeStore) Delete(ctx context.Context, id string) error
- func (s *SQLiteKnowledgeStore) Get(ctx context.Context, id string) (*KnowledgeEntry, error)
- func (s *SQLiteKnowledgeStore) GetByCategory(ctx context.Context, userID, category string) ([]KnowledgeEntry, error)
- func (s *SQLiteKnowledgeStore) GetByTags(ctx context.Context, userID string, tags []string) ([]KnowledgeEntry, error)
- func (s *SQLiteKnowledgeStore) GetStats(ctx context.Context, userID string) (int, error)
- func (s *SQLiteKnowledgeStore) RecordKnowledgeUse(ctx context.Context, id string) error
- func (s *SQLiteKnowledgeStore) Search(ctx context.Context, userID string, opts *SearchOptions) (*SearchResult, error)
- func (s *SQLiteKnowledgeStore) Update(ctx context.Context, entry KnowledgeEntry) error
- type SQLitePageIndexStore
- func (s *SQLitePageIndexStore) CountByUser(ctx context.Context, userID string) (int, error)
- func (s *SQLitePageIndexStore) Delete(ctx context.Context, userID, id string) error
- func (s *SQLitePageIndexStore) DeleteByKinds(ctx context.Context, userID string, kinds []PageIndexKind) error
- func (s *SQLitePageIndexStore) DeleteByUser(ctx context.Context, userID string) error
- func (s *SQLitePageIndexStore) Search(ctx context.Context, userID, query string, opts *PageIndexSearchOptions) ([]PageIndexHit, error)
- func (s *SQLitePageIndexStore) Upsert(ctx context.Context, doc PageIndexDoc) error
- type SQLitePreferenceStore
- func (s *SQLitePreferenceStore) Clear(ctx context.Context, userID string) error
- func (s *SQLitePreferenceStore) Delete(ctx context.Context, userID, category, key string) error
- func (s *SQLitePreferenceStore) Get(ctx context.Context, userID, category, key string) (*Preference, error)
- func (s *SQLitePreferenceStore) GetAllAsMap(ctx context.Context, userID string) (map[string]string, error)
- func (s *SQLitePreferenceStore) GetByCategory(ctx context.Context, userID, category string) ([]Preference, error)
- func (s *SQLitePreferenceStore) GetByUser(ctx context.Context, userID string) ([]Preference, error)
- func (s *SQLitePreferenceStore) Search(ctx context.Context, userID string, opts *SearchOptions) (*SearchResult, error)
- func (s *SQLitePreferenceStore) Set(ctx context.Context, pref Preference) error
- type SQLiteStore
- type SearchOptions
- type SearchResult
Constants ¶
const ( Phase2LockID = 1 Phase2Lease = 10 * time.Minute // 租约:认领后最长持有时间 Phase2Cooldown = 6 * time.Hour // 成功冷却:成功后 6h 内不再跑 )
const ( MemoryTypePreference = typescore.MemoryTypePreference MemoryTypeKnowledge = typescore.MemoryTypeKnowledge MemoryTypeIndex = typescore.MemoryTypeIndex PriorityLow = typescore.PriorityLow PriorityMedium = typescore.PriorityMedium PriorityHigh = typescore.PriorityHigh PageKindPreference = typescore.PageKindPreference PageKindKnowledge = typescore.PageKindKnowledge PageKindLongTerm = typescore.PageKindLongTerm PageKindKnowledgeBase = typescore.PageKindKnowledgeBase )
Variables ¶
var EstimateTokens = utils.EstimateTokens
var NewID = utils.NewID
var PageKeywordScore = utils.PageKeywordScore
Functions ¶
func DedupUserKnowledge ¶ added in v1.10.0
DedupUserKnowledge 对一个 user 的内容级重复条目做真收敛(评审 B1 修法)。
按 normalizeContentForDedup 分组的精确重复条目:
- 保留 updated_at 最新的一行(评审 R6 / task B2:保留行取最新、tags 并集);
- 其余行的 tags 并入保留行(评审 B1:行数真正收敛为 1,不再依赖 Add 的副作用);
- 保留行原 updated_at / usage_count / last_usage 不动(task B3:不刷平, PruneUnused 仍能按 updated_at < cutoff 剪枝);
- 删除其余重复行。
返回删除的行数。须在 Phase 2 全局锁内调用(Phase2Merge 迁移后收敛用)。
func IngestGetCursor ¶
func IngestIncStat ¶
func IngestSetCursor ¶
func MarkPhase2Cooldown ¶ added in v1.10.0
func MarkPhase2Cooldown(ctx context.Context, db *sql.DB, holder string, cooldown time.Duration) error
MarkPhase2Cooldown 记录一次成功合并,其它实例在 cooldown_until 前不再抢。
func MigrateLegacySessionKnowledge ¶ added in v1.10.0
MigrateLegacySessionKnowledge 迁移「user_id 是 sessionID 的旧条目」到归属 user。
幂等:已归拢(该 uid 不再是 knowledge/preferences 的 user_id 候选)的 session 不重复处理;重复执行不产生重复行。返回处理的条数(knowledge + preferences)。
func PruneUnused ¶ added in v1.10.0
PruneUnused 删除 max_unused_days 内未被引用且无使用计数的 knowledge 条目, 以及超期的 preferences。 对照 codex max_unused_days:usage_count > 0 的条目永不自动删除(被引用即豁免)。
func ReleasePhase2 ¶ added in v1.10.0
ReleasePhase2 释放全局锁(仅当 holder 匹配时)。
Types ¶
type IndexSearchResult ¶
type IndexSearchResult = typescore.IndexSearchResult
type KnowledgeEntry ¶
type KnowledgeEntry = typescore.KnowledgeEntry
type MemoryItem ¶
type MemoryItem = typescore.MemoryItem
type PageIndexDoc ¶
type PageIndexDoc = typescore.PageIndexDoc
type PageIndexHit ¶
type PageIndexHit = typescore.PageIndexHit
type PageIndexKind ¶
type PageIndexKind = typescore.PageIndexKind
type PageIndexSearchOptions ¶
type PageIndexSearchOptions = typescore.PageIndexSearchOptions
type Preference ¶
type Preference = typescore.Preference
type SQLiteIndexStore ¶
type SQLiteIndexStore struct {
// contains filtered or unexported fields
}
func NewSQLiteIndexStore ¶
func NewSQLiteIndexStore(store *SQLiteStore) *SQLiteIndexStore
func (*SQLiteIndexStore) CreateIndex ¶
func (*SQLiteIndexStore) DeleteIndex ¶
func (s *SQLiteIndexStore) DeleteIndex(ctx context.Context, userID, sourceID string) error
func (*SQLiteIndexStore) GetAllIndexes ¶
func (*SQLiteIndexStore) RemoveNode ¶
func (s *SQLiteIndexStore) RemoveNode(ctx context.Context, userID, sourceID, nodeID string) error
func (*SQLiteIndexStore) SearchIndex ¶
func (s *SQLiteIndexStore) SearchIndex(ctx context.Context, userID, query string, limit int) (*IndexSearchResult, error)
func (*SQLiteIndexStore) UpdateIndex ¶
func (s *SQLiteIndexStore) UpdateIndex(ctx context.Context, tree *IndexTree) error
func (*SQLiteIndexStore) UpdateNode ¶
type SQLiteKnowledgeStore ¶
type SQLiteKnowledgeStore struct {
// contains filtered or unexported fields
}
func NewSQLiteKnowledgeStore ¶
func NewSQLiteKnowledgeStore(store *SQLiteStore) *SQLiteKnowledgeStore
func (*SQLiteKnowledgeStore) Add ¶
func (s *SQLiteKnowledgeStore) Add(ctx context.Context, entry KnowledgeEntry) error
func (*SQLiteKnowledgeStore) Clear ¶
func (s *SQLiteKnowledgeStore) Clear(ctx context.Context, userID string) error
func (*SQLiteKnowledgeStore) DB ¶ added in v1.10.0
func (s *SQLiteKnowledgeStore) DB() *sql.DB
DB 暴露底层 *sql.DB(Phase 2 全局锁/剪枝直接操作 DB 用)。
func (*SQLiteKnowledgeStore) Delete ¶
func (s *SQLiteKnowledgeStore) Delete(ctx context.Context, id string) error
func (*SQLiteKnowledgeStore) Get ¶
func (s *SQLiteKnowledgeStore) Get(ctx context.Context, id string) (*KnowledgeEntry, error)
func (*SQLiteKnowledgeStore) GetByCategory ¶
func (s *SQLiteKnowledgeStore) GetByCategory(ctx context.Context, userID, category string) ([]KnowledgeEntry, error)
func (*SQLiteKnowledgeStore) GetByTags ¶
func (s *SQLiteKnowledgeStore) GetByTags(ctx context.Context, userID string, tags []string) ([]KnowledgeEntry, error)
func (*SQLiteKnowledgeStore) RecordKnowledgeUse ¶ added in v1.10.0
func (s *SQLiteKnowledgeStore) RecordKnowledgeUse(ctx context.Context, id string) error
RecordKnowledgeUse 记录一条知识被实际引用:usage_count + 1 并刷新 last_usage。 仅由「模型实际引用」路径调用(见 dino/mem 引用反馈),不用于「返回即计数」。
func (*SQLiteKnowledgeStore) Search ¶
func (s *SQLiteKnowledgeStore) Search(ctx context.Context, userID string, opts *SearchOptions) (*SearchResult, error)
func (*SQLiteKnowledgeStore) Update ¶
func (s *SQLiteKnowledgeStore) Update(ctx context.Context, entry KnowledgeEntry) error
type SQLitePageIndexStore ¶
type SQLitePageIndexStore struct {
// contains filtered or unexported fields
}
func NewSQLitePageIndexStore ¶
func NewSQLitePageIndexStore(store *SQLiteStore) *SQLitePageIndexStore
func (*SQLitePageIndexStore) CountByUser ¶
func (*SQLitePageIndexStore) Delete ¶
func (s *SQLitePageIndexStore) Delete(ctx context.Context, userID, id string) error
func (*SQLitePageIndexStore) DeleteByKinds ¶
func (s *SQLitePageIndexStore) DeleteByKinds(ctx context.Context, userID string, kinds []PageIndexKind) error
func (*SQLitePageIndexStore) DeleteByUser ¶
func (s *SQLitePageIndexStore) DeleteByUser(ctx context.Context, userID string) error
func (*SQLitePageIndexStore) Search ¶
func (s *SQLitePageIndexStore) Search(ctx context.Context, userID, query string, opts *PageIndexSearchOptions) ([]PageIndexHit, error)
func (*SQLitePageIndexStore) Upsert ¶
func (s *SQLitePageIndexStore) Upsert(ctx context.Context, doc PageIndexDoc) error
type SQLitePreferenceStore ¶
type SQLitePreferenceStore struct {
// contains filtered or unexported fields
}
func NewSQLitePreferenceStore ¶
func NewSQLitePreferenceStore(store *SQLiteStore) *SQLitePreferenceStore
func (*SQLitePreferenceStore) Clear ¶
func (s *SQLitePreferenceStore) Clear(ctx context.Context, userID string) error
func (*SQLitePreferenceStore) Delete ¶
func (s *SQLitePreferenceStore) Delete(ctx context.Context, userID, category, key string) error
func (*SQLitePreferenceStore) Get ¶
func (s *SQLitePreferenceStore) Get(ctx context.Context, userID, category, key string) (*Preference, error)
func (*SQLitePreferenceStore) GetAllAsMap ¶
func (*SQLitePreferenceStore) GetByCategory ¶
func (s *SQLitePreferenceStore) GetByCategory(ctx context.Context, userID, category string) ([]Preference, error)
func (*SQLitePreferenceStore) GetByUser ¶
func (s *SQLitePreferenceStore) GetByUser(ctx context.Context, userID string) ([]Preference, error)
func (*SQLitePreferenceStore) Search ¶
func (s *SQLitePreferenceStore) Search(ctx context.Context, userID string, opts *SearchOptions) (*SearchResult, error)
func (*SQLitePreferenceStore) Set ¶
func (s *SQLitePreferenceStore) Set(ctx context.Context, pref Preference) error
type SQLiteStore ¶
type SQLiteStore struct {
// contains filtered or unexported fields
}
func NewSQLiteStore ¶
func NewSQLiteStore(dbPath string) (*SQLiteStore, error)
func NewSQLiteStoreFromDB ¶
func NewSQLiteStoreFromDB(db *sql.DB) (*SQLiteStore, error)
func (*SQLiteStore) Close ¶
func (s *SQLiteStore) Close() error
func (*SQLiteStore) DB ¶
func (s *SQLiteStore) DB() *sql.DB
type SearchOptions ¶
type SearchOptions = typescore.SearchOptions
type SearchResult ¶
type SearchResult = typescore.SearchResult