storage

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RecordCleanupDeleted added in v0.3.5

func RecordCleanupDeleted(table string, count int64)

RecordCleanupDeleted records the number of deleted rows during cleanup.

func RecordCleanupDuration added in v0.3.5

func RecordCleanupDuration(table string, seconds float64)

RecordCleanupDuration records the duration of a cleanup operation.

func SetStorageSize added in v0.3.5

func SetStorageSize(bytes int64)

SetStorageSize updates the storage size metric.

func SetTableSize added in v0.3.5

func SetTableSize(table string, bytes int64)

SetTableSize updates the table size metric.

Types

type DashboardStats

type DashboardStats struct {
	TotalTopics         int
	AvgTopicSize        float64
	ProcessedTopicsPct  float64
	ConsolidatedTopics  int
	TotalFacts          int
	FactsByCategory     map[string]int
	FactsByType         map[string]int
	TotalMessages       int
	UnprocessedMessages int
	TotalRAGQueries     int
	AvgRAGCost          float64
	MessagesPerDay      map[string]int
	FactsGrowth         map[string]int
}

type Fact

type Fact struct {
	ID          int64
	UserID      int64
	Entity      string
	Relation    string
	Content     string
	Category    string
	Type        string // identity, context, status
	Importance  int    // 0-100
	Embedding   []float32
	TopicID     *int64 // Nullable
	CreatedAt   time.Time
	LastUpdated time.Time
}

type FactHistory

type FactHistory struct {
	ID           int64
	FactID       int64
	UserID       int64
	Action       string // add, update, delete
	OldContent   string
	NewContent   string
	Reason       string
	Category     string
	Entity       string
	Relation     string
	Importance   int
	TopicID      *int64
	CreatedAt    time.Time
	RequestInput string
}

type FactHistoryFilter

type FactHistoryFilter struct {
	UserID   int64
	Action   string
	Category string
	Search   string
}

type FactHistoryRepository

type FactHistoryRepository interface {
	AddFactHistory(history FactHistory) error
	UpdateFactHistoryTopic(oldTopicID, newTopicID int64) error
	GetFactHistory(userID int64, limit int) ([]FactHistory, error)
	GetFactHistoryExtended(filter FactHistoryFilter, limit, offset int, sortBy, sortDir string) (FactHistoryResult, error)
}

FactHistoryRepository handles fact history operations.

type FactHistoryResult

type FactHistoryResult struct {
	Data       []FactHistory
	TotalCount int
}

type FactRepository

type FactRepository interface {
	AddFact(fact Fact) (int64, error)
	GetFacts(userID int64) ([]Fact, error)
	GetFactsByIDs(ids []int64) ([]Fact, error)
	GetAllFacts() ([]Fact, error)
	GetFactsAfterID(minID int64) ([]Fact, error)
	GetFactStats() (FactStats, error)
	GetFactStatsByUser(userID int64) (FactStats, error)
	UpdateFact(fact Fact) error
	UpdateFactTopic(oldTopicID, newTopicID int64) error
	DeleteFact(userID, id int64) error
}

FactRepository handles fact operations.

type FactStats

type FactStats struct {
	CountByType map[string]int
	AvgAgeDays  float64
}

type LogRepository

type LogRepository interface {
	AddRAGLog(log RAGLog) error
	GetRAGLogs(userID int64, limit int) ([]RAGLog, error)
	GetTopicExtractionLogs(limit, offset int) ([]RAGLog, int, error)
}

LogRepository handles RAG log operations.

type MaintenanceRepository added in v0.3.5

type MaintenanceRepository interface {
	GetDBSize() (int64, error)
	GetTableSizes() ([]TableSize, error)
	CleanupFactHistory(keepPerUser int) (int64, error)
	CleanupRagLogs(keepPerUser int) (int64, error)
}

MaintenanceRepository handles database maintenance operations.

type MemoryBankRepository

type MemoryBankRepository interface {
	GetMemoryBank(userID int64) (string, error)
	UpdateMemoryBank(userID int64, content string) error
}

MemoryBankRepository handles the legacy memory bank.

type MergeCandidate

type MergeCandidate struct {
	Topic1 Topic
	Topic2 Topic
}

type Message

type Message struct {
	ID        int64
	UserID    int64
	Role      string
	Content   string
	TopicID   *int64 // Nullable
	CreatedAt time.Time
}

type MessageRepository

type MessageRepository interface {
	AddMessageToHistory(userID int64, message Message) error
	ImportMessage(userID int64, message Message) error
	GetRecentHistory(userID int64, limit int) ([]Message, error)
	GetMessagesByIDs(ids []int64) ([]Message, error)
	ClearHistory(userID int64) error
	GetMessagesInRange(ctx context.Context, userID int64, startID, endID int64) ([]Message, error)
	UpdateMessageTopic(messageID, topicID int64) error
	GetUnprocessedMessages(userID int64) ([]Message, error)
}

MessageRepository handles message history operations.

type RAGLog

type RAGLog struct {
	ID               int64
	UserID           int64
	OriginalQuery    string
	EnrichedQuery    string
	EnrichmentPrompt string
	ContextUsed      string // The full context sent to the generation model
	SystemPrompt     string
	RetrievalResults string // JSON array of retrieved messages
	LLMResponse      string
	EnrichmentTokens int
	GenerationTokens int
	TotalCostUSD     float64
	CreatedAt        time.Time
}

type SQLiteStore

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

func NewSQLiteStore

func NewSQLiteStore(logger *slog.Logger, path string) (*SQLiteStore, error)

func (*SQLiteStore) AddFact

func (s *SQLiteStore) AddFact(fact Fact) (int64, error)

func (*SQLiteStore) AddFactHistory

func (s *SQLiteStore) AddFactHistory(h FactHistory) error

func (*SQLiteStore) AddMessageToHistory

func (s *SQLiteStore) AddMessageToHistory(userID int64, message Message) error

func (*SQLiteStore) AddRAGLog

func (s *SQLiteStore) AddRAGLog(log RAGLog) error

func (*SQLiteStore) AddStat

func (s *SQLiteStore) AddStat(stat Stat) error

func (*SQLiteStore) AddTopic

func (s *SQLiteStore) AddTopic(topic Topic) (int64, error)

func (*SQLiteStore) CleanupFactHistory added in v0.3.5

func (s *SQLiteStore) CleanupFactHistory(keepPerUser int) (int64, error)

CleanupFactHistory removes old fact_history records, keeping only the N most recent per user. Returns the number of deleted rows.

func (*SQLiteStore) CleanupRagLogs added in v0.3.5

func (s *SQLiteStore) CleanupRagLogs(keepPerUser int) (int64, error)

CleanupRagLogs removes old rag_logs records, keeping only the N most recent per user. Returns the number of deleted rows.

func (*SQLiteStore) ClearHistory

func (s *SQLiteStore) ClearHistory(userID int64) error

func (*SQLiteStore) Close

func (s *SQLiteStore) Close() error

func (*SQLiteStore) CreateTopic

func (s *SQLiteStore) CreateTopic(topic Topic) (int64, error)

func (*SQLiteStore) DeleteFact

func (s *SQLiteStore) DeleteFact(userID, id int64) error

func (*SQLiteStore) DeleteTopic

func (s *SQLiteStore) DeleteTopic(id int64) error

func (*SQLiteStore) DeleteTopicCascade

func (s *SQLiteStore) DeleteTopicCascade(id int64) error

func (*SQLiteStore) GetAllFacts

func (s *SQLiteStore) GetAllFacts() ([]Fact, error)

func (*SQLiteStore) GetAllTopics

func (s *SQLiteStore) GetAllTopics() ([]Topic, error)

func (*SQLiteStore) GetAllUsers

func (s *SQLiteStore) GetAllUsers() ([]User, error)

func (*SQLiteStore) GetDBSize added in v0.3.5

func (s *SQLiteStore) GetDBSize() (int64, error)

GetDBSize returns the size of the database file in bytes.

func (*SQLiteStore) GetDashboardStats

func (s *SQLiteStore) GetDashboardStats(userID int64) (*DashboardStats, error)

func (*SQLiteStore) GetFactHistory

func (s *SQLiteStore) GetFactHistory(userID int64, limit int) ([]FactHistory, error)

func (*SQLiteStore) GetFactHistoryExtended

func (s *SQLiteStore) GetFactHistoryExtended(filter FactHistoryFilter, limit, offset int, sortBy, sortDir string) (FactHistoryResult, error)

func (*SQLiteStore) GetFactStats

func (s *SQLiteStore) GetFactStats() (FactStats, error)

func (*SQLiteStore) GetFactStatsByUser added in v0.3.5

func (s *SQLiteStore) GetFactStatsByUser(userID int64) (FactStats, error)

func (*SQLiteStore) GetFacts

func (s *SQLiteStore) GetFacts(userID int64) ([]Fact, error)

func (*SQLiteStore) GetFactsAfterID added in v0.2.1

func (s *SQLiteStore) GetFactsAfterID(minID int64) ([]Fact, error)

func (*SQLiteStore) GetFactsByIDs

func (s *SQLiteStore) GetFactsByIDs(ids []int64) ([]Fact, error)

func (*SQLiteStore) GetLastTopicEndMessageID

func (s *SQLiteStore) GetLastTopicEndMessageID(userID int64) (int64, error)

func (*SQLiteStore) GetMemoryBank

func (s *SQLiteStore) GetMemoryBank(userID int64) (string, error)

func (*SQLiteStore) GetMergeCandidates

func (s *SQLiteStore) GetMergeCandidates(userID int64) ([]MergeCandidate, error)

func (*SQLiteStore) GetMessagesByIDs

func (s *SQLiteStore) GetMessagesByIDs(ids []int64) ([]Message, error)

func (*SQLiteStore) GetMessagesInRange

func (s *SQLiteStore) GetMessagesInRange(ctx context.Context, userID int64, startID, endID int64) ([]Message, error)

func (*SQLiteStore) GetRAGLogs

func (s *SQLiteStore) GetRAGLogs(userID int64, limit int) ([]RAGLog, error)

func (*SQLiteStore) GetRecentHistory

func (s *SQLiteStore) GetRecentHistory(userID int64, limit int) ([]Message, error)

func (*SQLiteStore) GetStats

func (s *SQLiteStore) GetStats() (map[int64]Stat, error)

func (*SQLiteStore) GetTableSizes added in v0.3.5

func (s *SQLiteStore) GetTableSizes() ([]TableSize, error)

GetTableSizes returns the size of each table in bytes using SQLite's dbstat virtual table.

func (*SQLiteStore) GetTopicExtractionLogs

func (s *SQLiteStore) GetTopicExtractionLogs(limit, offset int) ([]RAGLog, int, error)

func (*SQLiteStore) GetTopics

func (s *SQLiteStore) GetTopics(userID int64) ([]Topic, error)

func (*SQLiteStore) GetTopicsAfterID added in v0.2.1

func (s *SQLiteStore) GetTopicsAfterID(minID int64) ([]Topic, error)

func (*SQLiteStore) GetTopicsByIDs added in v0.2.1

func (s *SQLiteStore) GetTopicsByIDs(ids []int64) ([]Topic, error)

func (*SQLiteStore) GetTopicsExtended

func (s *SQLiteStore) GetTopicsExtended(filter TopicFilter, limit, offset int, sortBy, sortDir string) (TopicResult, error)

func (*SQLiteStore) GetTopicsPendingFacts

func (s *SQLiteStore) GetTopicsPendingFacts(userID int64) ([]Topic, error)

func (*SQLiteStore) GetUnprocessedMessages

func (s *SQLiteStore) GetUnprocessedMessages(userID int64) ([]Message, error)

func (*SQLiteStore) ImportMessage

func (s *SQLiteStore) ImportMessage(userID int64, message Message) error

func (*SQLiteStore) Init

func (s *SQLiteStore) Init() error

func (*SQLiteStore) ResetUserData

func (s *SQLiteStore) ResetUserData(userID int64) error

func (*SQLiteStore) SetTopicConsolidationChecked

func (s *SQLiteStore) SetTopicConsolidationChecked(topicID int64, checked bool) error

func (*SQLiteStore) SetTopicFactsExtracted

func (s *SQLiteStore) SetTopicFactsExtracted(topicID int64, extracted bool) error

func (*SQLiteStore) UpdateFact

func (s *SQLiteStore) UpdateFact(fact Fact) error

func (*SQLiteStore) UpdateFactHistoryTopic

func (s *SQLiteStore) UpdateFactHistoryTopic(oldTopicID, newTopicID int64) error

func (*SQLiteStore) UpdateFactTopic

func (s *SQLiteStore) UpdateFactTopic(oldTopicID, newTopicID int64) error

func (*SQLiteStore) UpdateMemoryBank

func (s *SQLiteStore) UpdateMemoryBank(userID int64, content string) error

func (*SQLiteStore) UpdateMessageTopic

func (s *SQLiteStore) UpdateMessageTopic(messageID, topicID int64) error

func (*SQLiteStore) UpsertUser

func (s *SQLiteStore) UpsertUser(user User) error

type Stat

type Stat struct {
	UserID     int64
	TokensUsed int
	CostUSD    float64
}

type StatsRepository

type StatsRepository interface {
	AddStat(stat Stat) error
	GetStats() (map[int64]Stat, error)
	GetDashboardStats(userID int64) (*DashboardStats, error)
}

StatsRepository handles usage statistics.

type TableSize added in v0.3.5

type TableSize struct {
	Name  string
	Bytes int64
}

TableSize represents the size of a database table.

type Topic

type Topic struct {
	ID                   int64
	UserID               int64
	Summary              string
	StartMsgID           int64
	EndMsgID             int64
	Embedding            []float32
	FactsExtracted       bool
	IsConsolidated       bool
	ConsolidationChecked bool
	CreatedAt            time.Time
}

type TopicExtended

type TopicExtended struct {
	Topic
	FactsCount   int
	MessageCount int
}

type TopicFilter

type TopicFilter struct {
	UserID         int64
	Search         string
	HasFacts       *bool // nil = all, true = yes, false = no
	IsConsolidated *bool // nil = all
	TopicID        *int64
}

type TopicRepository

type TopicRepository interface {
	AddTopic(topic Topic) (int64, error)
	CreateTopic(topic Topic) (int64, error)
	DeleteTopic(id int64) error
	DeleteTopicCascade(id int64) error
	GetLastTopicEndMessageID(userID int64) (int64, error)
	GetAllTopics() ([]Topic, error)
	GetTopicsAfterID(minID int64) ([]Topic, error)
	GetTopicsByIDs(ids []int64) ([]Topic, error)
	GetTopics(userID int64) ([]Topic, error)
	SetTopicFactsExtracted(topicID int64, extracted bool) error
	SetTopicConsolidationChecked(topicID int64, checked bool) error
	GetTopicsPendingFacts(userID int64) ([]Topic, error)
	GetTopicsExtended(filter TopicFilter, limit, offset int, sortBy, sortDir string) (TopicResult, error)
	GetMergeCandidates(userID int64) ([]MergeCandidate, error)
}

TopicRepository handles topic operations.

type TopicResult

type TopicResult struct {
	Data       []TopicExtended
	TotalCount int
}

type User

type User struct {
	ID        int64
	Username  string
	FirstName string
	LastName  string
	LastSeen  time.Time
}

type UserRepository

type UserRepository interface {
	UpsertUser(user User) error
	GetAllUsers() ([]User, error)
	ResetUserData(userID int64) error
}

UserRepository handles user data operations.

Jump to

Keyboard shortcuts

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