storage

package
v0.1.0-beta Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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)
	GetFactStats() (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 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) 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) 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) GetFacts

func (s *SQLiteStore) GetFacts(userID 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) GetTopicExtractionLogs

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

func (*SQLiteStore) GetTopics

func (s *SQLiteStore) GetTopics(userID 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 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)
	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