storage

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TagInnerCircle    = "inner_circle"    // Work_Inner + Family, system prompt
	TagRelevantPeople = "relevant_people" // Reranker selected, user prompt
	TagPeople         = "people"          // All people, for Archivist
)

XML tag constants for people formatting.

Variables

This section is empty.

Functions

func FormatPeople added in v0.5.1

func FormatPeople(people []Person, tag string) string

FormatPeople formats people list with specified XML tag. Format: [Person:ID] Name (@username, aka Alias1, Alias2) [Circle]: Bio If tag is empty, outputs plain list without XML wrapper.

func FormatRecentTopics added in v0.4.8

func FormatRecentTopics(topics []TopicExtended) string

FormatRecentTopics formats recent topics for inclusion in agent prompts. Returns content wrapped in <recent_topics> tags. Format: - date: "summary" (N msg, ~Xk chars)

func FormatUserProfile added in v0.4.8

func FormatUserProfile(facts []Fact) string

FormatUserProfile formats user facts for inclusion in agent prompts. Returns content wrapped in <user_profile> tags. Format: - [ID:X] Category/Type (Updated: date) Content

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 AgentLog added in v0.4.8

type AgentLog struct {
	ID                int64
	UserID            int64
	AgentType         string // laplace, reranker, splitter, merger, enricher, archivist, scout
	InputPrompt       string
	InputContext      string // JSON - full OpenRouter API request
	OutputResponse    string
	OutputParsed      string // JSON - structured output
	OutputContext     string // JSON - full OpenRouter API response
	Model             string
	PromptTokens      int
	CompletionTokens  int
	TotalCost         *float64
	DurationMs        int
	Metadata          string // JSON - agent-specific data
	Success           bool
	ErrorMessage      string
	ConversationTurns string // JSON - all request/response turns for multi-turn agents
	CreatedAt         time.Time
}

AgentLog stores debug traces from LLM agent calls (unified logging for all agents)

type AgentLogFilter added in v0.4.8

type AgentLogFilter struct {
	UserID    int64
	AgentType string
	Success   *bool
	Search    string
}

AgentLogFilter for filtering agent logs

type AgentLogRepository added in v0.4.8

type AgentLogRepository interface {
	AddAgentLog(log AgentLog) error
	GetAgentLogs(agentType string, userID int64, limit int) ([]AgentLog, error)
	GetAgentLogsExtended(filter AgentLogFilter, limit, offset int) (AgentLogResult, error)
}

AgentLogRepository handles unified agent debug log operations.

type AgentLogResult added in v0.4.8

type AgentLogResult struct {
	Data       []AgentLog
	TotalCount int
}

AgentLogResult wraps agent logs with total count for pagination

type CheckpointResult added in v0.4.6

type CheckpointResult struct {
	Busy         int // 0 = success, 1 = blocked by reader
	Log          int // Total frames in WAL file
	Checkpointed int // Frames actually checkpointed
}

CheckpointResult contains the result of a WAL checkpoint operation.

type ContaminatedTopic added in v0.4.6

type ContaminatedTopic struct {
	TopicID       int64   `json:"topic_id"`
	TopicOwner    int64   `json:"topic_owner"`
	TopicSummary  string  `json:"topic_summary"`
	ForeignUsers  []int64 `json:"foreign_users"`
	ForeignMsgCnt int     `json:"foreign_msg_count"`
	TotalMsgCnt   int     `json:"total_msg_count"`
}

ContaminatedTopic represents a topic containing messages from other users.

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
	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
}

func FilterProfileFacts added in v0.4.8

func FilterProfileFacts(facts []Fact) []Fact

FilterProfileFacts filters facts to identity and high-importance facts only. This is the standard filter used across all agents.

type FactHistory

type FactHistory struct {
	ID           int64
	FactID       int64
	UserID       int64
	Action       string // add, update, delete
	OldContent   string
	NewContent   string
	Reason       string
	Category     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)
	GetFactsByTopicID(topicID 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 MaintenanceRepository added in v0.3.5

type MaintenanceRepository interface {
	GetDBSize() (int64, error)
	GetTableSizes() ([]TableSize, error)
	CleanupFactHistory(keepPerUser int) (int64, error)
	CleanupAgentLogs(keepPerUserPerAgent int) (int64, error)
	CountAgentLogs() (int64, error)
	CountFactHistory() (int64, error)

	// Database health diagnostics
	CountOrphanedTopics(userID int64) (int, error)
	GetOrphanedTopicIDs(userID int64) ([]int64, error)
	CountOverlappingTopics(userID int64) (int, error)
	GetOverlappingTopics(userID int64) ([]OverlappingPair, error)
	CountFactsOnOrphanedTopics(userID int64) (int, error)
	RecalculateTopicRanges(userID int64) (int, error)
	RecalculateTopicSizes(userID int64) (int, error)

	// Cross-user contamination detection and repair
	GetContaminatedTopics(userID int64) ([]ContaminatedTopic, error)
	CountContaminatedTopics(userID int64) (int, error)
	FixContaminatedTopics(userID int64) (int64, error)

	// WAL checkpoint for ensuring data persistence
	Checkpoint() 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)
	GetMessagesByTopicID(ctx context.Context, topicID int64) ([]Message, error)
	UpdateMessageTopic(messageID, topicID int64) error
	UpdateMessagesTopicInRange(ctx context.Context, userID, startMsgID, endMsgID, topicID int64) error
	GetUnprocessedMessages(userID int64) ([]Message, error)
}

MessageRepository handles message history operations.

type OverlappingPair added in v0.4.6

type OverlappingPair struct {
	Topic1ID      int64
	Topic1Summary string
	Topic2ID      int64
	Topic2Summary string
}

OverlappingPair contains information about two overlapping topics.

type PeopleRepository added in v0.5.1

type PeopleRepository interface {
	// CRUD operations
	AddPerson(person Person) (int64, error)
	UpdatePerson(person Person) error
	DeletePerson(userID, personID int64) error

	// Retrieval
	GetPerson(userID, personID int64) (*Person, error)
	GetPeople(userID int64) ([]Person, error)
	GetPeopleByIDs(ids []int64) ([]Person, error)
	GetAllPeople() ([]Person, error)
	GetPeopleAfterID(minID int64) ([]Person, error)

	// Direct matching (fast path for @username and name lookup)
	FindPersonByTelegramID(userID, telegramID int64) (*Person, error)
	FindPersonByUsername(userID int64, username string) (*Person, error)
	FindPersonByAlias(userID int64, alias string) ([]Person, error)
	FindPersonByName(userID int64, name string) (*Person, error)

	// Merge operations
	MergePeople(userID, targetID, sourceID int64, newBio string, newAliases []string) error

	// Extended queries with filtering and pagination
	GetPeopleExtended(filter PersonFilter, limit, offset int, sortBy, sortDir string) (PersonResult, error)

	// Maintenance
	CountPeopleWithoutEmbedding(userID int64) (int, error)
	GetPeopleWithoutEmbedding(userID int64) ([]Person, error)
}

PeopleRepository handles people from the user's social graph.

type Person added in v0.5.1

type Person struct {
	ID           int64     `json:"id"`
	UserID       int64     `json:"user_id"`
	DisplayName  string    `json:"display_name"`
	Aliases      []string  `json:"aliases"`     // JSON array: ["Гелёй", "@akaGelo"]
	TelegramID   *int64    `json:"telegram_id"` // For direct @mention match
	Username     *string   `json:"username"`    // @username without @
	Circle       string    `json:"circle"`      // Family, Friends, Work_Inner, Work_Outer, Other
	Bio          string    `json:"bio"`         // Aggregated profile (2-3 sentences)
	Embedding    []float32 `json:"embedding"`   // Bio vector (JSON float32 array)
	FirstSeen    time.Time `json:"first_seen"`
	LastSeen     time.Time `json:"last_seen"`
	MentionCount int       `json:"mention_count"`
}

Person represents a person from the user's social graph.

func FilterInnerCircle added in v0.5.1

func FilterInnerCircle(people []Person) []Person

FilterInnerCircle returns only Work_Inner and Family people.

type PersonFilter added in v0.5.1

type PersonFilter struct {
	UserID int64
	Circle string
	Search string
}

PersonFilter for filtering people queries.

type PersonResult added in v0.5.1

type PersonResult struct {
	Data       []Person
	TotalCount int
}

PersonResult wraps people with total count for pagination.

type RerankerCandidate added in v0.4.1

type RerankerCandidate struct {
	TopicID      int64   `json:"topic_id"`
	Summary      string  `json:"summary"`
	Score        float32 `json:"score"`
	Date         string  `json:"date"`
	MessageCount int     `json:"message_count"`
	SizeChars    int     `json:"size_chars"`
}

RerankerCandidate is a single candidate for JSON serialization

type RerankerToolCall added in v0.4.1

type RerankerToolCall struct {
	Iteration int                     `json:"iteration"`
	TopicIDs  []int64                 `json:"topic_ids"`
	Topics    []RerankerToolCallTopic `json:"topics"`
}

RerankerToolCall represents one iteration of tool calls

type RerankerToolCallTopic added in v0.4.1

type RerankerToolCallTopic struct {
	ID      int64  `json:"id"`
	Summary string `json:"summary"`
}

RerankerToolCallTopic contains topic info for tool call display

type SQLiteStore

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

func NewSQLiteStore

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

func (*SQLiteStore) AddAgentLog added in v0.4.8

func (s *SQLiteStore) AddAgentLog(log AgentLog) error

AddAgentLog inserts a new agent log entry.

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) AddPerson added in v0.5.1

func (s *SQLiteStore) AddPerson(person Person) (int64, error)

AddPerson creates a new person record. Returns the new person ID.

func (*SQLiteStore) AddStat

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

func (*SQLiteStore) AddTopic

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

func (*SQLiteStore) AddTopicWithoutMessageUpdate added in v0.4.6

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

AddTopicWithoutMessageUpdate creates a topic without updating message references. Used when manually managing message-topic relationships (e.g., during topic splitting).

func (*SQLiteStore) Checkpoint added in v0.4.6

func (s *SQLiteStore) Checkpoint() error

Checkpoint forces a WAL checkpoint to flush all pending writes to the main database file. This is useful before shutdown or after critical writes to ensure data persistence. Returns CheckpointResult with details about what was checkpointed.

func (*SQLiteStore) CleanupAgentLogs added in v0.4.8

func (s *SQLiteStore) CleanupAgentLogs(keepPerUserPerAgent int) (int64, error)

CleanupAgentLogs removes old agent_logs records, keeping only the N most recent per user per agent type. Returns the number of deleted rows.

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) ClearHistory

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

func (*SQLiteStore) Close

func (s *SQLiteStore) Close() error

func (*SQLiteStore) CountAgentLogs added in v0.4.8

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

CountAgentLogs returns the total number of agent_logs records.

func (*SQLiteStore) CountContaminatedTopics added in v0.4.6

func (s *SQLiteStore) CountContaminatedTopics(userID int64) (int, error)

CountContaminatedTopics counts topics with cross-user contamination. If userID is 0, counts all; otherwise only for specified user.

func (*SQLiteStore) CountFactHistory added in v0.4.8

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

CountFactHistory returns the total number of fact_history records.

func (*SQLiteStore) CountFactsOnOrphanedTopics added in v0.4.6

func (s *SQLiteStore) CountFactsOnOrphanedTopics(userID int64) (int, error)

CountFactsOnOrphanedTopics counts facts linked to orphaned topics. If userID is 0, counts for all users.

func (*SQLiteStore) CountOrphanedTopics added in v0.4.6

func (s *SQLiteStore) CountOrphanedTopics(userID int64) (int, error)

CountOrphanedTopics counts topics with no messages linked to them. If userID is 0, counts for all users.

func (*SQLiteStore) CountOverlappingTopics added in v0.4.6

func (s *SQLiteStore) CountOverlappingTopics(userID int64) (int, error)

CountOverlappingTopics counts pairs of topics with overlapping message ranges. If userID is 0, counts for all users.

func (*SQLiteStore) CountPeopleWithoutEmbedding added in v0.5.1

func (s *SQLiteStore) CountPeopleWithoutEmbedding(userID int64) (int, error)

CountPeopleWithoutEmbedding returns count of people missing embeddings.

func (*SQLiteStore) CreateTopic

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

func (*SQLiteStore) DeleteAllFacts added in v0.5.3

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

DeleteAllFacts removes all facts for a user in a single query.

func (*SQLiteStore) DeleteAllPeople added in v0.5.3

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

DeleteAllPeople removes all people for a user in a single query.

func (*SQLiteStore) DeleteAllTopics added in v0.5.3

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

DeleteAllTopics removes all topics for a user in a single query.

func (*SQLiteStore) DeleteFact

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

func (*SQLiteStore) DeletePerson added in v0.5.1

func (s *SQLiteStore) DeletePerson(userID, personID int64) error

DeletePerson removes a person record.

func (*SQLiteStore) DeleteTopic

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

func (*SQLiteStore) DeleteTopicCascade

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

func (*SQLiteStore) FindPersonByAlias added in v0.5.1

func (s *SQLiteStore) FindPersonByAlias(userID int64, alias string) ([]Person, error)

FindPersonByAlias finds people whose aliases contain the given string. Returns multiple matches since aliases might overlap.

func (*SQLiteStore) FindPersonByName added in v0.5.1

func (s *SQLiteStore) FindPersonByName(userID int64, name string) (*Person, error)

FindPersonByName finds a person by their display name (exact match).

func (*SQLiteStore) FindPersonByTelegramID added in v0.5.1

func (s *SQLiteStore) FindPersonByTelegramID(userID, telegramID int64) (*Person, error)

FindPersonByTelegramID finds a person by their Telegram ID.

func (*SQLiteStore) FindPersonByUsername added in v0.5.1

func (s *SQLiteStore) FindPersonByUsername(userID int64, username string) (*Person, error)

FindPersonByUsername finds a person by their @username (without @).

func (*SQLiteStore) FixContaminatedTopics added in v0.4.6

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

FixContaminatedTopics removes foreign messages from contaminated topics by setting their topic_id to NULL. Returns the number of messages unlinked. If userID is 0, fixes all; otherwise only topics owned by specified user.

func (*SQLiteStore) GetAgentLogs added in v0.4.8

func (s *SQLiteStore) GetAgentLogs(agentType string, userID int64, limit int) ([]AgentLog, error)

GetAgentLogs returns the most recent agent logs for a specific agent type. If userID is 0, returns logs for all users.

func (*SQLiteStore) GetAgentLogsExtended added in v0.4.8

func (s *SQLiteStore) GetAgentLogsExtended(filter AgentLogFilter, limit, offset int) (AgentLogResult, error)

GetAgentLogsExtended returns agent logs with filtering and pagination.

func (*SQLiteStore) GetAllFacts

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

func (*SQLiteStore) GetAllPeople added in v0.5.1

func (s *SQLiteStore) GetAllPeople() ([]Person, error)

GetAllPeople retrieves all people across all users (for vector index loading).

func (*SQLiteStore) GetAllTopics

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

func (*SQLiteStore) GetAllUsers

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

func (*SQLiteStore) GetContaminatedTopics added in v0.4.6

func (s *SQLiteStore) GetContaminatedTopics(userID int64) ([]ContaminatedTopic, error)

GetContaminatedTopics finds topics that contain messages from users other than the topic owner. If userID is 0, checks all topics; otherwise only topics owned by userID.

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) GetFactsByTopicID added in v0.4.6

func (s *SQLiteStore) GetFactsByTopicID(topicID 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) GetMessagesByTopicID added in v0.4.6

func (s *SQLiteStore) GetMessagesByTopicID(ctx context.Context, topicID int64) ([]Message, error)

func (*SQLiteStore) GetMessagesInRange

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

func (*SQLiteStore) GetOrphanedTopicIDs added in v0.4.6

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

GetOrphanedTopicIDs returns IDs of topics with no messages linked. If userID is 0, returns for all users.

func (*SQLiteStore) GetOverlappingTopics added in v0.4.6

func (s *SQLiteStore) GetOverlappingTopics(userID int64) ([]OverlappingPair, error)

GetOverlappingTopics returns pairs of topics with overlapping message ranges. If userID is 0, returns for all users.

func (*SQLiteStore) GetPeople added in v0.5.1

func (s *SQLiteStore) GetPeople(userID int64) ([]Person, error)

GetPeople retrieves all people for a user.

func (*SQLiteStore) GetPeopleAfterID added in v0.5.1

func (s *SQLiteStore) GetPeopleAfterID(minID int64) ([]Person, error)

GetPeopleAfterID retrieves people created after a given ID (for incremental index updates).

func (*SQLiteStore) GetPeopleByIDs added in v0.5.1

func (s *SQLiteStore) GetPeopleByIDs(ids []int64) ([]Person, error)

GetPeopleByIDs retrieves people by their IDs.

func (*SQLiteStore) GetPeopleExtended added in v0.5.1

func (s *SQLiteStore) GetPeopleExtended(filter PersonFilter, limit, offset int, sortBy, sortDir string) (PersonResult, error)

GetPeopleExtended retrieves people with filtering and pagination.

func (*SQLiteStore) GetPeopleWithoutEmbedding added in v0.5.1

func (s *SQLiteStore) GetPeopleWithoutEmbedding(userID int64) ([]Person, error)

GetPeopleWithoutEmbedding returns people missing embeddings.

func (*SQLiteStore) GetPerson added in v0.5.1

func (s *SQLiteStore) GetPerson(userID, personID int64) (*Person, error)

GetPerson retrieves a single person by ID.

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) 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) MergePeople added in v0.5.1

func (s *SQLiteStore) MergePeople(userID, targetID, sourceID int64, newBio string, newAliases []string) error

MergePeople merges source person into target person, then deletes source.

func (*SQLiteStore) RecalculateTopicRanges added in v0.4.6

func (s *SQLiteStore) RecalculateTopicRanges(userID int64) (int, error)

RecalculateTopicRanges recalculates start_msg_id and end_msg_id for all topics based on actual message assignments. If userID is 0, recalculates for all users.

func (*SQLiteStore) RecalculateTopicSizes added in v0.4.6

func (s *SQLiteStore) RecalculateTopicSizes(userID int64) (int, error)

RecalculateTopicSizes recalculates size_chars for all topics based on actual message content. If userID is 0, recalculates for all users.

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) UpdateMessagesTopicInRange added in v0.4.6

func (s *SQLiteStore) UpdateMessagesTopicInRange(ctx context.Context, userID, startMsgID, endMsgID, topicID int64) error

func (*SQLiteStore) UpdatePerson added in v0.5.1

func (s *SQLiteStore) UpdatePerson(person Person) error

UpdatePerson updates an existing person record.

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
	SizeChars            int // Total character count of all messages in topic
	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)
	AddTopicWithoutMessageUpdate(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