store

package
v0.9.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DirectMessageGuildID = "@me"
View Source
const (
	EmbeddingInputVersion = "message_normalized_v1"
)

Variables

View Source
var ErrNoCompatibleEmbeddings = errors.New("no compatible message embeddings for provider/model/input version; run discrawl embed --rebuild")
View Source
var ErrSchemaVersionMismatch = errors.New("database schema version mismatch")

Functions

func DecodeEmbeddingVector

func DecodeEmbeddingVector(blob []byte) ([]float32, error)

func DefaultEmbedLimit

func DefaultEmbedLimit() int

func EncodeEmbeddingVector

func EncodeEmbeddingVector(values []float32) ([]byte, error)

func IsReadOnlySQL

func IsReadOnlySQL(query string) bool

Types

type AttachmentListOptions added in v0.8.0

type AttachmentListOptions struct {
	GuildIDs        []string
	ExcludeGuildIDs []string
	ChannelIDs      []string
	Channel         string
	Author          string
	MessageID       string
	Filename        string
	ContentType     string
	Since           time.Time
	Before          time.Time
	Limit           int
	MissingOnly     bool
}

type AttachmentMediaUpdate added in v0.8.0

type AttachmentMediaUpdate struct {
	AttachmentID  string
	MediaPath     string
	ContentSHA256 string
	ContentSize   int64
	FetchedAt     string
	FetchStatus   string
	FetchError    string
}

type AttachmentRecord

type AttachmentRecord struct {
	AttachmentID  string
	MessageID     string
	GuildID       string
	ChannelID     string
	AuthorID      string
	Filename      string
	ContentType   string
	Size          int64
	URL           string
	ProxyURL      string
	TextContent   string
	MediaPath     string
	ContentSHA256 string
	ContentSize   int64
	FetchedAt     string
	FetchStatus   string
	FetchError    string
}

type AttachmentRow added in v0.8.0

type AttachmentRow struct {
	AttachmentID  string    `json:"attachment_id"`
	MessageID     string    `json:"message_id"`
	GuildID       string    `json:"guild_id"`
	GuildName     string    `json:"guild_name,omitempty"`
	ChannelID     string    `json:"channel_id"`
	ChannelName   string    `json:"channel_name"`
	AuthorID      string    `json:"author_id"`
	AuthorName    string    `json:"author_name"`
	Filename      string    `json:"filename"`
	ContentType   string    `json:"content_type,omitempty"`
	Size          int64     `json:"size"`
	URL           string    `json:"url,omitempty"`
	ProxyURL      string    `json:"proxy_url,omitempty"`
	TextContent   string    `json:"text_content,omitempty"`
	MediaPath     string    `json:"media_path,omitempty"`
	ContentSHA256 string    `json:"content_sha256,omitempty"`
	ContentSize   int64     `json:"content_size,omitempty"`
	FetchedAt     time.Time `json:"fetched_at,omitzero"`
	FetchStatus   string    `json:"fetch_status,omitempty"`
	FetchError    string    `json:"fetch_error,omitempty"`
	CreatedAt     time.Time `json:"created_at"`
}

type ChannelRecord

type ChannelRecord struct {
	ID               string
	GuildID          string
	ParentID         string
	Kind             string
	Name             string
	Topic            string
	Position         int
	IsNSFW           bool
	IsArchived       bool
	IsLocked         bool
	IsPrivateThread  bool
	ThreadParentID   string
	ArchiveTimestamp string
	RawJSON          string
}

type ChannelRow

type ChannelRow struct {
	ID               string    `json:"id"`
	GuildID          string    `json:"guild_id"`
	ParentID         string    `json:"parent_id,omitempty"`
	Kind             string    `json:"kind"`
	Name             string    `json:"name"`
	Topic            string    `json:"topic,omitempty"`
	Position         int       `json:"position"`
	IsNSFW           bool      `json:"is_nsfw"`
	IsArchived       bool      `json:"is_archived"`
	IsLocked         bool      `json:"is_locked"`
	IsPrivateThread  bool      `json:"is_private_thread"`
	ThreadParentID   string    `json:"thread_parent_id,omitempty"`
	ArchiveTimestamp time.Time `json:"archive_timestamp,omitzero"`
}

type DirectMessageConversationOptions

type DirectMessageConversationOptions struct {
	With  string
	Limit int
}

type DirectMessageConversationRow

type DirectMessageConversationRow struct {
	ChannelID      string    `json:"channel_id"`
	Name           string    `json:"name"`
	MessageCount   int       `json:"message_count"`
	AuthorCount    int       `json:"author_count"`
	FirstMessageAt time.Time `json:"first_message_at,omitzero"`
	LastMessageAt  time.Time `json:"last_message_at,omitzero"`
}

type EmbeddingDrainOptions

type EmbeddingDrainOptions struct {
	Provider      string
	Model         string
	InputVersion  string
	Limit         int
	BatchSize     int
	MaxInputChars int
	Now           func() time.Time
}

type EmbeddingDrainStats

type EmbeddingDrainStats struct {
	Processed        int    `json:"processed"`
	Succeeded        int    `json:"succeeded"`
	Failed           int    `json:"failed"`
	Skipped          int    `json:"skipped"`
	Requeued         int    `json:"requeued,omitempty"`
	RemainingBacklog int    `json:"remaining_backlog"`
	Provider         string `json:"provider"`
	Model            string `json:"model"`
	InputVersion     string `json:"input_version"`
	RateLimited      bool   `json:"rate_limited,omitempty"`
}

type GuildRecord

type GuildRecord struct {
	ID      string
	Name    string
	Icon    string
	RawJSON string
}

type MemberProfile

type MemberProfile struct {
	Member         MemberRow    `json:"member"`
	RawJSON        string       `json:"raw_json,omitempty"`
	MessageCount   int          `json:"message_count"`
	FirstMessageAt time.Time    `json:"first_message_at,omitzero"`
	LastMessageAt  time.Time    `json:"last_message_at,omitzero"`
	RecentMessages []MessageRow `json:"recent_messages,omitempty"`
}

type MemberRecord

type MemberRecord struct {
	GuildID       string
	UserID        string
	Username      string
	GlobalName    string
	DisplayName   string
	Nick          string
	Discriminator string
	Avatar        string
	Bot           bool
	JoinedAt      string
	RoleIDsJSON   string
	RawJSON       string
}

type MemberRow

type MemberRow struct {
	GuildID       string    `json:"guild_id"`
	UserID        string    `json:"user_id"`
	Username      string    `json:"username"`
	GlobalName    string    `json:"global_name,omitempty"`
	DisplayName   string    `json:"display_name,omitempty"`
	Nick          string    `json:"nick,omitempty"`
	Discriminator string    `json:"discriminator,omitempty"`
	Avatar        string    `json:"avatar,omitempty"`
	RoleIDsJSON   string    `json:"role_ids_json"`
	Bot           bool      `json:"bot"`
	JoinedAt      time.Time `json:"joined_at,omitzero"`
	Bio           string    `json:"bio,omitempty"`
	Pronouns      string    `json:"pronouns,omitempty"`
	Location      string    `json:"location,omitempty"`
	Website       string    `json:"website,omitempty"`
	XHandle       string    `json:"x_handle,omitempty"`
	GitHubLogin   string    `json:"github_login,omitempty"`
	URLs          []string  `json:"urls,omitempty"`
	RawJSON       string    `json:"-"`
}

type MentionEventRecord

type MentionEventRecord struct {
	MessageID  string
	GuildID    string
	ChannelID  string
	AuthorID   string
	TargetType string
	TargetID   string
	TargetName string
	EventAt    string
}

type MentionListOptions

type MentionListOptions struct {
	GuildIDs   []string
	Channel    string
	Author     string
	Target     string
	TargetType string
	Since      time.Time
	Before     time.Time
	Limit      int
}

type MentionRow

type MentionRow struct {
	MessageID   string    `json:"message_id"`
	GuildID     string    `json:"guild_id"`
	ChannelID   string    `json:"channel_id"`
	ChannelName string    `json:"channel_name"`
	AuthorID    string    `json:"author_id"`
	AuthorName  string    `json:"author_name"`
	TargetType  string    `json:"target_type"`
	TargetID    string    `json:"target_id"`
	TargetName  string    `json:"target_name"`
	Content     string    `json:"content"`
	CreatedAt   time.Time `json:"created_at"`
}

type MessageListOptions

type MessageListOptions struct {
	GuildIDs     []string
	Channel      string
	Author       string
	Since        time.Time
	Before       time.Time
	Limit        int
	Last         int
	IncludeEmpty bool
}

type MessageMutation

type MessageMutation struct {
	Record      MessageRecord
	EventType   string
	PayloadJSON string
	Options     WriteOptions
	Attachments []AttachmentRecord
	Mentions    []MentionEventRecord
}

type MessageRecord

type MessageRecord struct {
	ID                string
	GuildID           string
	ChannelID         string
	ChannelName       string
	AuthorID          string
	AuthorName        string
	MessageType       int
	CreatedAt         string
	EditedAt          string
	DeletedAt         string
	Content           string
	NormalizedContent string
	ReplyToMessageID  string
	Pinned            bool
	HasAttachments    bool
	RawJSON           string
}

type MessageRow

type MessageRow struct {
	MessageID       string    `json:"message_id"`
	GuildID         string    `json:"guild_id"`
	GuildName       string    `json:"guild_name,omitempty"`
	ChannelID       string    `json:"channel_id"`
	ChannelName     string    `json:"channel_name"`
	AuthorID        string    `json:"author_id"`
	AuthorName      string    `json:"author_name"`
	Content         string    `json:"content"`
	DisplayContent  string    `json:"display_content,omitempty"`
	CreatedAt       time.Time `json:"created_at"`
	ReplyToMessage  string    `json:"reply_to_message_id,omitempty"`
	Source          string    `json:"source,omitempty"`
	HasAttachments  bool      `json:"has_attachments"`
	AttachmentNames string    `json:"attachment_names,omitempty"`
	AttachmentText  string    `json:"attachment_text,omitempty"`
	Pinned          bool      `json:"pinned"`
}

type SearchOptions

type SearchOptions struct {
	Query        string
	GuildIDs     []string
	Channel      string
	Author       string
	Limit        int
	IncludeEmpty bool
}

type SearchResult

type SearchResult struct {
	MessageID   string    `json:"message_id"`
	GuildID     string    `json:"guild_id"`
	ChannelID   string    `json:"channel_id"`
	ChannelName string    `json:"channel_name"`
	AuthorID    string    `json:"author_id"`
	AuthorName  string    `json:"author_name"`
	Content     string    `json:"content"`
	CreatedAt   time.Time `json:"created_at"`
}

type SemanticSearchOptions

type SemanticSearchOptions struct {
	QueryVector  []float32
	Provider     string
	Model        string
	InputVersion string
	Dimensions   int
	GuildIDs     []string
	Channel      string
	Author       string
	Limit        int
	IncludeEmpty bool
}

type Status

type Status struct {
	DBPath             string    `json:"db_path"`
	GuildCount         int       `json:"guild_count"`
	ChannelCount       int       `json:"channel_count"`
	ThreadCount        int       `json:"thread_count"`
	MessageCount       int       `json:"message_count"`
	MemberCount        int       `json:"member_count"`
	EmbeddingBacklog   int       `json:"embedding_backlog"`
	LastSyncAt         time.Time `json:"last_sync_at,omitzero"`
	LastTailEventAt    time.Time `json:"last_tail_event_at,omitzero"`
	DefaultGuildID     string    `json:"default_guild_id,omitempty"`
	DefaultGuildName   string    `json:"default_guild_name,omitempty"`
	AccessibleGuildIDs []string  `json:"accessible_guild_ids,omitempty"`
}

type Store

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

func Open

func Open(ctx context.Context, path string) (*Store, error)

func OpenReadOnly

func OpenReadOnly(ctx context.Context, path string) (*Store, error)

func (*Store) AppendMessageEvent

func (s *Store) AppendMessageEvent(ctx context.Context, guildID, channelID, messageID, eventType string, payload any) error

func (*Store) ChannelMessageBounds

func (s *Store) ChannelMessageBounds(ctx context.Context, channelID string) (string, string, error)

func (*Store) Channels

func (s *Store) Channels(ctx context.Context, guildID string) ([]ChannelRow, error)

func (*Store) CheckMessageFTS

func (s *Store) CheckMessageFTS(ctx context.Context) error

func (*Store) Close

func (s *Store) Close() error

func (*Store) DB

func (s *Store) DB() *sql.DB

func (*Store) DeleteGuildData

func (s *Store) DeleteGuildData(ctx context.Context, guildID string) error

func (*Store) DeleteMember

func (s *Store) DeleteMember(ctx context.Context, guildID, userID string) error

func (*Store) DeleteOrphanChannels

func (s *Store) DeleteOrphanChannels(ctx context.Context, guildID string) error

func (*Store) DeleteSyncState

func (s *Store) DeleteSyncState(ctx context.Context, scope string) error

func (*Store) DirectMessageConversations

func (s *Store) DirectMessageConversations(ctx context.Context, opts DirectMessageConversationOptions) ([]DirectMessageConversationRow, error)

func (*Store) DrainEmbeddingJobs

func (s *Store) DrainEmbeddingJobs(ctx context.Context, provider embed.Provider, opts EmbeddingDrainOptions) (EmbeddingDrainStats, error)

func (*Store) EmbeddingBacklog

func (s *Store) EmbeddingBacklog(ctx context.Context) (int, error)

func (*Store) Exec

func (s *Store) Exec(ctx context.Context, query string) (int64, error)

func (*Store) ExpandAttachmentChannelIDs added in v0.8.0

func (s *Store) ExpandAttachmentChannelIDs(ctx context.Context, channelIDs []string) ([]string, error)

func (*Store) GetSyncState

func (s *Store) GetSyncState(ctx context.Context, scope string) (string, error)

func (*Store) GuildChannelCount

func (s *Store) GuildChannelCount(ctx context.Context, guildID string) (int, error)

func (*Store) GuildMemberCount

func (s *Store) GuildMemberCount(ctx context.Context, guildID string) (int, error)

func (*Store) HasMessageEmbeddings

func (s *Store) HasMessageEmbeddings(ctx context.Context, provider, model, inputVersion string) (bool, error)

func (*Store) IncompleteMessageChannelIDs

func (s *Store) IncompleteMessageChannelIDs(ctx context.Context, guildID string) ([]string, error)

func (*Store) ListAttachments added in v0.8.0

func (s *Store) ListAttachments(ctx context.Context, opts AttachmentListOptions) ([]AttachmentRow, error)

func (*Store) ListMentions

func (s *Store) ListMentions(ctx context.Context, opts MentionListOptions) ([]MentionRow, error)

func (*Store) ListMessages

func (s *Store) ListMessages(ctx context.Context, opts MessageListOptions) ([]MessageRow, error)

func (*Store) ListMessagesWithThreadContext

func (s *Store) ListMessagesWithThreadContext(ctx context.Context, opts MessageListOptions) ([]MessageRow, error)

func (*Store) MarkMessageDeleted

func (s *Store) MarkMessageDeleted(ctx context.Context, guildID, channelID, messageID string, payload any) error

func (*Store) MemberByID

func (s *Store) MemberByID(ctx context.Context, userID string) ([]MemberRow, error)

func (*Store) MemberProfile

func (s *Store) MemberProfile(ctx context.Context, guildID, userID string, recentLimit int) (MemberProfile, error)

func (*Store) Members

func (s *Store) Members(ctx context.Context, guildID, query string, limit int) ([]MemberRow, error)

func (*Store) Query

func (s *Store) Query(ctx context.Context, query string) ([]string, [][]string, error)

func (*Store) ReadOnlyQuery

func (s *Store) ReadOnlyQuery(ctx context.Context, query string) ([]string, [][]string, error)

func (*Store) RebuildMemberSearchIndex added in v0.7.2

func (s *Store) RebuildMemberSearchIndex(ctx context.Context) error

func (*Store) RebuildMessageSearchIndex added in v0.7.2

func (s *Store) RebuildMessageSearchIndex(ctx context.Context) error

func (*Store) RebuildSearchIndexes

func (s *Store) RebuildSearchIndexes(ctx context.Context) error

func (*Store) ReplaceMembers

func (s *Store) ReplaceMembers(ctx context.Context, guildID string, members []MemberRecord) error

func (*Store) RequeueAllEmbeddingJobs

func (s *Store) RequeueAllEmbeddingJobs(ctx context.Context, opts EmbeddingDrainOptions) (int, error)

func (*Store) SearchMessages

func (s *Store) SearchMessages(ctx context.Context, opts SearchOptions) ([]SearchResult, error)

func (*Store) SearchMessagesHybrid

func (s *Store) SearchMessagesHybrid(ctx context.Context, opts SearchOptions, semanticOpts SemanticSearchOptions) ([]SearchResult, error)

func (*Store) SearchMessagesSemantic

func (s *Store) SearchMessagesSemantic(ctx context.Context, opts SemanticSearchOptions) ([]SearchResult, error)

func (*Store) SetSyncState

func (s *Store) SetSyncState(ctx context.Context, scope, cursor string) error

func (*Store) Status

func (s *Store) Status(ctx context.Context, dbPath, defaultGuildID string) (Status, error)

func (*Store) UpdateAttachmentFetchStatus added in v0.8.0

func (s *Store) UpdateAttachmentFetchStatus(ctx context.Context, attachmentID, fetchedAt, status, message string) error

func (*Store) UpdateAttachmentMedia added in v0.8.0

func (s *Store) UpdateAttachmentMedia(ctx context.Context, update AttachmentMediaUpdate) error

func (*Store) UpsertChannel

func (s *Store) UpsertChannel(ctx context.Context, channel ChannelRecord) error

func (*Store) UpsertGuild

func (s *Store) UpsertGuild(ctx context.Context, guild GuildRecord) error

func (*Store) UpsertMember

func (s *Store) UpsertMember(ctx context.Context, member MemberRecord) error

func (*Store) UpsertMessage

func (s *Store) UpsertMessage(ctx context.Context, message MessageRecord) error

func (*Store) UpsertMessageWithOptions

func (s *Store) UpsertMessageWithOptions(ctx context.Context, message MessageRecord, opts WriteOptions) error

func (*Store) UpsertMessages

func (s *Store) UpsertMessages(ctx context.Context, messages []MessageMutation) error

type WriteOptions

type WriteOptions struct {
	AppendEvent      bool
	EnqueueEmbedding bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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