sqlite

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Phase2LockID   = 1
	Phase2Lease    = 10 * time.Minute // 租约:认领后最长持有时间
	Phase2Cooldown = 6 * time.Hour    // 成功冷却:成功后 6h 内不再跑

)
View Source
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

View Source
var EstimateTokens = utils.EstimateTokens
View Source
var NewID = utils.NewID
View Source
var PageKeywordScore = utils.PageKeywordScore

Functions

func DedupUserKnowledge added in v1.10.0

func DedupUserKnowledge(ctx context.Context, db *sql.DB, userID string) (int, error)

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 IngestGetCursor(ctx context.Context, db *sql.DB, sessionID string) (int64, error)

func IngestIncStat

func IngestIncStat(ctx context.Context, db *sql.DB, sessionID, ruleName string) error

func IngestSetCursor

func IngestSetCursor(ctx context.Context, db *sql.DB, sessionID string, lastMessageID int64) error

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

func MigrateLegacySessionKnowledge(ctx context.Context, db *sql.DB) (int, error)

MigrateLegacySessionKnowledge 迁移「user_id 是 sessionID 的旧条目」到归属 user。

幂等:已归拢(该 uid 不再是 knowledge/preferences 的 user_id 候选)的 session 不重复处理;重复执行不产生重复行。返回处理的条数(knowledge + preferences)。

func PruneUnused added in v1.10.0

func PruneUnused(ctx context.Context, db *sql.DB, maxUnusedDays int) error

PruneUnused 删除 max_unused_days 内未被引用且无使用计数的 knowledge 条目, 以及超期的 preferences。 对照 codex max_unused_days:usage_count > 0 的条目永不自动删除(被引用即豁免)。

func ReleasePhase2 added in v1.10.0

func ReleasePhase2(ctx context.Context, db *sql.DB, holder string) error

ReleasePhase2 释放全局锁(仅当 holder 匹配时)。

func TryClaimPhase2 added in v1.10.0

func TryClaimPhase2(ctx context.Context, db *sql.DB, holder string, lease, cooldown time.Duration) (bool, error)

TryClaimPhase2 以 SQLite 方言认领全局锁。仅当「无持有者 / 租约过期 / 冷却已过」 时可抢到,返回是否认领成功。

Types

type IndexNode

type IndexNode = typescore.IndexNode

type IndexSearchResult

type IndexSearchResult = typescore.IndexSearchResult

type IndexTree

type IndexTree = typescore.IndexTree

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 Priority

type Priority = typescore.Priority

type SQLiteIndexStore

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

func NewSQLiteIndexStore

func NewSQLiteIndexStore(store *SQLiteStore) *SQLiteIndexStore

func (*SQLiteIndexStore) AddNode

func (s *SQLiteIndexStore) AddNode(ctx context.Context, userID, sourceID string, node *IndexNode, parentID string) error

func (*SQLiteIndexStore) CreateIndex

func (s *SQLiteIndexStore) CreateIndex(ctx context.Context, userID, sourceID, title string, nodes []*IndexNode) (*IndexTree, error)

func (*SQLiteIndexStore) DeleteIndex

func (s *SQLiteIndexStore) DeleteIndex(ctx context.Context, userID, sourceID string) error

func (*SQLiteIndexStore) GetAllIndexes

func (s *SQLiteIndexStore) GetAllIndexes(ctx context.Context, userID string) ([]*IndexTree, error)

func (*SQLiteIndexStore) GetIndex

func (s *SQLiteIndexStore) GetIndex(ctx context.Context, userID, sourceID string) (*IndexTree, error)

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

func (s *SQLiteIndexStore) UpdateNode(ctx context.Context, userID, sourceID string, node *IndexNode) error

type SQLiteKnowledgeStore

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

func NewSQLiteKnowledgeStore

func NewSQLiteKnowledgeStore(store *SQLiteStore) *SQLiteKnowledgeStore

func (*SQLiteKnowledgeStore) Add

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 (*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) GetStats

func (s *SQLiteKnowledgeStore) GetStats(ctx context.Context, userID string) (int, 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

type SQLitePageIndexStore

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

func NewSQLitePageIndexStore

func NewSQLitePageIndexStore(store *SQLiteStore) *SQLitePageIndexStore

func (*SQLitePageIndexStore) CountByUser

func (s *SQLitePageIndexStore) CountByUser(ctx context.Context, userID string) (int, error)

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

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 (s *SQLitePreferenceStore) GetAllAsMap(ctx context.Context, userID string) (map[string]string, error)

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

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

Jump to

Keyboard shortcuts

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