sqlcdb

package
v0.0.0-...-9692abd Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Annotation

type Annotation struct {
	ID         uuid.UUID
	OwnerID    uuid.UUID
	DocumentID uuid.UUID
	BlockID    string
	Kind       string
	Selector   []byte
	Note       pgtype.Text
	Version    int32
	CreatedAt  time.Time
	UpdatedAt  time.Time
}

type BumpIndexSeqParams

type BumpIndexSeqParams struct {
	OwnerID uuid.UUID
	ID      uuid.UUID
}

type ChatSpentTodayRow

type ChatSpentTodayRow struct {
	SpentMicrousd        int64
	SecondsUntilMidnight float64
}

type ChatUsageParams

type ChatUsageParams struct {
	WindowSeconds float64
	OwnerID       uuid.UUID
}

type ChatUsageRow

type ChatUsageRow struct {
	Questions                        int32
	InputTokens                      int64
	SecondsUntilOldestQuestionLeaves float64
	SecondsUntilOldestAnswerLeaves   float64
}

type ChunkToSearchRow

type ChunkToSearchRow struct {
	OwnerID uuid.UUID
	Word    string
}

type CountAnnotationsParams

type CountAnnotationsParams struct {
	OwnerID    uuid.UUID
	DocumentID uuid.UUID
}

type CountDocumentChunksParams

type CountDocumentChunksParams struct {
	OwnerID    uuid.UUID
	DocumentID uuid.UUID
}

type CountRunningAnswersParams

type CountRunningAnswersParams struct {
	OwnerID           uuid.UUID
	ConversationID    uuid.UUID
	RunningForSeconds float64
}

type CreateAnnotationParams

type CreateAnnotationParams struct {
	OwnerID    uuid.UUID
	DocumentID uuid.UUID
	BlockID    string
	Kind       string
	Selector   []byte
	Note       pgtype.Text
}

type CreateConversationParams

type CreateConversationParams struct {
	OwnerID    uuid.UUID
	DocumentID uuid.NullUUID
}

type CreateDocumentIfAbsentParams

type CreateDocumentIfAbsentParams struct {
	OwnerID      uuid.UUID
	SourceID     uuid.UUID
	ExtractionID uuid.UUID
	Title        string
	Content      []byte
}

type CreateDocumentIfAbsentRow

type CreateDocumentIfAbsentRow struct {
	ID      uuid.UUID
	Created bool
}

type CreateIdentityParams

type CreateIdentityParams struct {
	Provider       string
	ProviderUserID string
	UserID         uuid.UUID
	Login          string
}

type CreateImportParams

type CreateImportParams struct {
	OwnerID      uuid.UUID
	RequestedURL string
	CanonicalURL string
}

type CreatePDFImportParams

type CreatePDFImportParams struct {
	OwnerID   uuid.UUID
	Filename  string
	PDFSHA256 string
}

type CreateSessionParams

type CreateSessionParams struct {
	TokenHash       []byte
	UserID          uuid.UUID
	LifetimeSeconds float64
}

type CreateUserParams

type CreateUserParams struct {
	Email       string
	DisplayName string
}

type DBTX

type DBTX interface {
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
}

type DeleteAnnotationParams

type DeleteAnnotationParams struct {
	OwnerID uuid.UUID
	ID      uuid.UUID
}

type DeleteAnnotationRow

type DeleteAnnotationRow struct {
	DocumentID uuid.UUID
	Note       pgtype.Text
}

type DeleteConversationParams

type DeleteConversationParams struct {
	OwnerID uuid.UUID
	ID      uuid.UUID
}

type DeleteDocumentChunksParams

type DeleteDocumentChunksParams struct {
	OwnerID    uuid.UUID
	DocumentID uuid.UUID
}

type DeleteDocumentConversationsParams

type DeleteDocumentConversationsParams struct {
	OwnerID    uuid.UUID
	DocumentID uuid.NullUUID
}

type DeleteDocumentParams

type DeleteDocumentParams struct {
	OwnerID uuid.UUID
	ID      uuid.UUID
}

type DeletePDFSourceParams

type DeletePDFSourceParams struct {
	SourceID uuid.UUID
	OwnerID  uuid.UUID
}

type DocumentExtractionParams

type DocumentExtractionParams struct {
	OwnerID uuid.UUID
	ID      uuid.UUID
}

type DocumentOriginalParams

type DocumentOriginalParams struct {
	OwnerID uuid.UUID
	ID      uuid.UUID
}

type DocumentOriginalRow

type DocumentOriginalRow struct {
	BlobKey  string
	Filename string
}

type DocumentVersionParams

type DocumentVersionParams struct {
	OwnerID uuid.UUID
	ID      uuid.UUID
}

type DocumentsBehindParams

type DocumentsBehindParams struct {
	Model   string
	MaxRows int32
}

type DocumentsBehindRow

type DocumentsBehindRow struct {
	OwnerID  uuid.UUID
	ID       uuid.UUID
	IndexSeq int64
}

type FailImportParams

type FailImportParams struct {
	ErrorCode pgtype.Text
	OwnerID   uuid.UUID
	ID        uuid.UUID
}

type FindOwnerDocumentForURLParams

type FindOwnerDocumentForURLParams struct {
	OwnerID uuid.UUID
	URL     string
}

type FindOwnerPDFDocumentParams

type FindOwnerPDFDocumentParams struct {
	OwnerID   uuid.UUID
	PDFSHA256 string
}

type FindSourceForURLRow

type FindSourceForURLRow struct {
	ID            uuid.UUID
	CanonicalURL  string
	FinalURL      string
	ETag          string
	LastModified  string
	LastFetchedAt time.Time
}

type FinishImportParams

type FinishImportParams struct {
	DocumentID uuid.NullUUID
	OwnerID    uuid.UUID
	ID         uuid.UUID
}

type FinishMessageParams

type FinishMessageParams struct {
	Status                   string
	Content                  []byte
	Model                    string
	InputTokens              int32
	OutputTokens             int32
	CacheCreationInputTokens int32
	CacheReadInputTokens     int32
	CostMicrousd             int64
	FirstTokenMs             int32
	LatencyMs                int32
	ToolRounds               int32
	InvalidCitations         int32
	SelfMarkers              int32
	OwnerID                  uuid.UUID
	ID                       uuid.UUID
}

type FinishMessageRow

type FinishMessageRow struct {
	ID                       uuid.UUID
	ConversationID           uuid.UUID
	Role                     string
	Status                   string
	Content                  []byte
	Model                    string
	InputTokens              int32
	OutputTokens             int32
	CacheCreationInputTokens int32
	CacheReadInputTokens     int32
	CostMicrousd             int64
	FirstTokenMs             int32
	LatencyMs                int32
	ToolRounds               int32
	InvalidCitations         int32
	SelfMarkers              int32
	CreatedAt                time.Time
}

type GetAccountParams

type GetAccountParams struct {
	ID       uuid.UUID
	Provider string
}

type GetAccountRow

type GetAccountRow struct {
	ID          uuid.UUID
	Email       string
	DisplayName string
	Login       string
}

type GetAnnotationParams

type GetAnnotationParams struct {
	OwnerID uuid.UUID
	ID      uuid.UUID
}

type GetCachedEmbeddingsParams

type GetCachedEmbeddingsParams struct {
	Model  string
	Hashes [][]byte
}

type GetCachedEmbeddingsRow

type GetCachedEmbeddingsRow struct {
	TextSha256 []byte
	Embedding  pgvector.HalfVector
}

type GetConversationParams

type GetConversationParams struct {
	OwnerID uuid.UUID
	ID      uuid.UUID
}

type GetConversationRow

type GetConversationRow struct {
	ID            uuid.UUID
	DocumentID    uuid.NullUUID
	DocumentTitle string
	Title         string
	CreatedAt     time.Time
	UpdatedAt     time.Time
}

type GetDocumentParams

type GetDocumentParams struct {
	OwnerID uuid.UUID
	ID      uuid.UUID
}

type GetDocumentRow

type GetDocumentRow struct {
	ID        uuid.UUID
	Title     string
	SourceURL string
	Version   int32
	CreatedAt time.Time
	UpdatedAt time.Time
	Content   []byte
	Warnings  []byte
	PDF       []byte
}

type GetIdentityParams

type GetIdentityParams struct {
	Provider       string
	ProviderUserID string
}

type GetImportParams

type GetImportParams struct {
	OwnerID uuid.UUID
	ID      uuid.UUID
}

type GetIndexStateParams

type GetIndexStateParams struct {
	OwnerID uuid.UUID
	ID      uuid.UUID
}

type GetIndexStateRow

type GetIndexStateRow struct {
	Title      string
	Content    []byte
	IndexSeq   int64
	IndexedSeq int64
}

type GetSessionParams

type GetSessionParams struct {
	TokenHash    []byte
	TouchSeconds float64
	IdleSeconds  float64
}

type GetSessionRow

type GetSessionRow struct {
	UserID     uuid.UUID
	LastSeenAt time.Time
	Stale      bool
}

type Import

type Import struct {
	ID           uuid.UUID
	OwnerID      uuid.UUID
	RequestedURL pgtype.Text
	CanonicalURL pgtype.Text
	Status       string
	ErrorCode    pgtype.Text
	DocumentID   uuid.NullUUID
	CreatedAt    time.Time
	UpdatedAt    time.Time
	Kind         string
	Filename     pgtype.Text
	PDFSHA256    pgtype.Text
	PdfPages     pgtype.Int4
}

type InsertChunkParams

type InsertChunkParams struct {
	OwnerID     uuid.UUID
	DocumentID  uuid.UUID
	BlockIDs    []string
	BlockTexts  []string
	HeadingPath []string
	Kind        string
	Text        string
	Lang        string
	Position    int32
	Headings    string
	Prose       string
	Code        string
	Idents      string
	Embedding   *pgvector.HalfVector
	Model       string
}

type InsertMessageParams

type InsertMessageParams struct {
	ConversationID uuid.UUID
	OwnerID        uuid.UUID
	Role           string
	Status         string
	Content        []byte
}

type InsertMessageRow

type InsertMessageRow struct {
	ID                       uuid.UUID
	ConversationID           uuid.UUID
	Role                     string
	Status                   string
	Content                  []byte
	Model                    string
	InputTokens              int32
	OutputTokens             int32
	CacheCreationInputTokens int32
	CacheReadInputTokens     int32
	CostMicrousd             int64
	FirstTokenMs             int32
	LatencyMs                int32
	ToolRounds               int32
	InvalidCitations         int32
	SelfMarkers              int32
	CreatedAt                time.Time
}

type LatestImportForDocumentParams

type LatestImportForDocumentParams struct {
	OwnerID    uuid.UUID
	DocumentID uuid.NullUUID
}

type ListAnnotationsParams

type ListAnnotationsParams struct {
	OwnerID    uuid.UUID
	DocumentID uuid.UUID
}

type ListConversationsParams

type ListConversationsParams struct {
	OwnerID         uuid.UUID
	BeforeUpdatedAt time.Time
	BeforeID        uuid.UUID
	MaxRows         int32
}

type ListConversationsRow

type ListConversationsRow struct {
	ID            uuid.UUID
	DocumentID    uuid.NullUUID
	DocumentTitle string
	Title         string
	CreatedAt     time.Time
	UpdatedAt     time.Time
}

type ListDocumentsParams

type ListDocumentsParams struct {
	OwnerID         uuid.UUID
	BeforeCreatedAt time.Time
	BeforeID        uuid.UUID
	MaxRows         int32
}

type ListDocumentsRow

type ListDocumentsRow struct {
	ID        uuid.UUID
	Title     string
	SourceURL string
	Version   int32
	CreatedAt time.Time
	UpdatedAt time.Time
	PDF       []byte
}

type ListMessagesParams

type ListMessagesParams struct {
	RunningForSeconds float64
	OwnerID           uuid.UUID
	ConversationID    uuid.UUID
}

type ListMessagesRow

type ListMessagesRow struct {
	ID                       uuid.UUID
	ConversationID           uuid.UUID
	Role                     string
	Status                   string
	Content                  []byte
	Model                    string
	InputTokens              int32
	OutputTokens             int32
	CacheCreationInputTokens int32
	CacheReadInputTokens     int32
	CostMicrousd             int64
	FirstTokenMs             int32
	LatencyMs                int32
	ToolRounds               int32
	InvalidCitations         int32
	SelfMarkers              int32
	CreatedAt                time.Time
}

type LockConversationParams

type LockConversationParams struct {
	OwnerID uuid.UUID
	ID      uuid.UUID
}

type LockDocumentContentParams

type LockDocumentContentParams struct {
	OwnerID uuid.UUID
	ID      uuid.UUID
}

type MarkIndexedParams

type MarkIndexedParams struct {
	Seq     int64
	OwnerID uuid.UUID
	ID      uuid.UUID
}

type NewestSnapshotRow

type NewestSnapshotRow struct {
	ID          uuid.UUID
	SourceID    uuid.UUID
	BodySHA256  string
	BodyGzip    []byte
	ContentType string
	FetchedAt   time.Time
}

type PutCachedEmbeddingParams

type PutCachedEmbeddingParams struct {
	Model      string
	TextSha256 []byte
	Embedding  pgvector.HalfVector
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) BlobKeysInUse

func (q *Queries) BlobKeysInUse(ctx context.Context, keys []string) ([]string, error)

The keys among keys that a PDF snapshot holds, or that an unfinished PDF import of its owner will read.

func (*Queries) BumpIndexSeq

func (q *Queries) BumpIndexSeq(ctx context.Context, arg BumpIndexSeqParams) (int64, error)

Records a change search sees; the new sequence keys the index job.

func (*Queries) ChatSpentToday

func (q *Queries) ChatSpentToday(ctx context.Context) (ChatSpentTodayRow, error)

What every user's answers have cost since midnight UTC, and how long until the next one.

func (*Queries) ChatUsage

func (q *Queries) ChatUsage(ctx context.Context, arg ChatUsageParams) (ChatUsageRow, error)

What counts against the owner's chat quotas within the window: questions asked, and the input tokens their answers read, with how long until the oldest of each leaves the window.

func (*Queries) ChunkToSearch

func (q *Queries) ChunkToSearch(ctx context.Context) (ChunkToSearchRow, error)

The restore drill's search (docs/adr/0015-operations.md): the newest chunk's owner and a word it is indexed by, which it searches its owner's library for. The word is one of its lexemes, which full-text search kept, so never a stopword; the longest, as the most particular.

func (*Queries) CountAnnotations

func (q *Queries) CountAnnotations(ctx context.Context, arg CountAnnotationsParams) (int64, error)

func (*Queries) CountDocumentChunks

func (q *Queries) CountDocumentChunks(ctx context.Context, arg CountDocumentChunksParams) (int32, error)

func (*Queries) CountRunningAnswers

func (q *Queries) CountRunningAnswers(ctx context.Context, arg CountRunningAnswersParams) (int32, error)

Answers in the conversation still streaming, unless they have been for longer than any answer runs.

func (*Queries) CreateAnnotation

func (q *Queries) CreateAnnotation(ctx context.Context, arg CreateAnnotationParams) (Annotation, error)

func (*Queries) CreateConversation

func (q *Queries) CreateConversation(ctx context.Context, arg CreateConversationParams) (uuid.UUID, error)

Every query here is scoped by owner_id; TestOwnedQueriesAreScoped checks it. The owner's new conversation, about document when it is theirs, else over their library. No row when document isn't the owner's.

func (*Queries) CreateDocumentIfAbsent

func (q *Queries) CreateDocumentIfAbsent(ctx context.Context, arg CreateDocumentIfAbsentParams) (CreateDocumentIfAbsentRow, error)

Creates the owner's document for a source, or returns the one they already have. created is false when it already existed.

func (*Queries) CreateIdentity

func (q *Queries) CreateIdentity(ctx context.Context, arg CreateIdentityParams) error

func (*Queries) CreateImport

func (q *Queries) CreateImport(ctx context.Context, arg CreateImportParams) (Import, error)

Every query here is scoped by owner_id; TestOwnedQueriesAreScoped checks it.

func (*Queries) CreatePDFImport

func (q *Queries) CreatePDFImport(ctx context.Context, arg CreatePDFImportParams) (Import, error)

func (*Queries) CreateSession

func (q *Queries) CreateSession(ctx context.Context, arg CreateSessionParams) error

func (*Queries) CreateUser

func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error)

func (*Queries) DeleteAnnotation

func (q *Queries) DeleteAnnotation(ctx context.Context, arg DeleteAnnotationParams) (DeleteAnnotationRow, error)

func (*Queries) DeleteConversation

func (q *Queries) DeleteConversation(ctx context.Context, arg DeleteConversationParams) (int64, error)

func (*Queries) DeleteDocument

func (q *Queries) DeleteDocument(ctx context.Context, arg DeleteDocumentParams) (uuid.UUID, error)

Deletes the owner's document; its annotations and chunks go with it, and the imports that made it keep their row without it. Returns its source.

func (*Queries) DeleteDocumentChunks

func (q *Queries) DeleteDocumentChunks(ctx context.Context, arg DeleteDocumentChunksParams) error

Every query on chunks is scoped by owner_id; TestOwnedQueriesAreScoped checks it.

func (*Queries) DeleteDocumentConversations

func (q *Queries) DeleteDocumentConversations(ctx context.Context, arg DeleteDocumentConversationsParams) ([]uuid.UUID, error)

Deletes the conversations about the owner's document, before the document itself, and names them so their answers can be stopped.

func (*Queries) DeletePDFSource

func (q *Queries) DeletePDFSource(ctx context.Context, arg DeletePDFSourceParams) ([]string, error)

Deletes the owner's PDF source once no document of theirs uses it, with its snapshots and extractions, and returns its snapshots' blob keys.

func (*Queries) DeleteSession

func (q *Queries) DeleteSession(ctx context.Context, tokenHash []byte) error

func (*Queries) DeleteUser

func (q *Queries) DeleteUser(ctx context.Context, id uuid.UUID) (int64, error)

Everything the user owns goes with them; shared sources stay.

func (*Queries) DeleteUserSessions

func (q *Queries) DeleteUserSessions(ctx context.Context, userID uuid.UUID) error

func (*Queries) DocumentExtraction

func (q *Queries) DocumentExtraction(ctx context.Context, arg DocumentExtractionParams) ([]byte, error)

The IR of the extraction the owner's document was made from.

func (*Queries) DocumentOriginal

func (q *Queries) DocumentOriginal(ctx context.Context, arg DocumentOriginalParams) (DocumentOriginalRow, error)

The blob key and filename of the PDF the owner's document was made from.

func (*Queries) DocumentVersion

func (q *Queries) DocumentVersion(ctx context.Context, arg DocumentVersionParams) (int32, error)

func (*Queries) DocumentsBehind

func (q *Queries) DocumentsBehind(ctx context.Context, arg DocumentsBehindParams) ([]DocumentsBehindRow, error)

Every user's documents whose chunks are behind their content, or were embedded by another model: the worker's backfill, across owners.

func (*Queries) FailImport

func (q *Queries) FailImport(ctx context.Context, arg FailImportParams) (Import, error)

Marks an import that has not finished as failed with a stable error code.

func (*Queries) FindOwnerDocumentForURL

func (q *Queries) FindOwnerDocumentForURL(ctx context.Context, arg FindOwnerDocumentForURLParams) (uuid.UUID, error)

Every query here is scoped by owner_id; TestOwnedQueriesAreScoped checks it. The owner's document for url: a document whose source has url as its canonical or final URL, or one an earlier import of url produced.

func (*Queries) FindOwnerPDFDocument

func (q *Queries) FindOwnerPDFDocument(ctx context.Context, arg FindOwnerPDFDocumentParams) (uuid.UUID, error)

The owner's document made from the PDF with this SHA-256.

func (*Queries) FindSourceForURL

func (q *Queries) FindSourceForURL(ctx context.Context, url string) (FindSourceForURLRow, error)

The web source whose canonical URL, or else whose final URL, is url.

func (*Queries) FinishImport

func (q *Queries) FinishImport(ctx context.Context, arg FinishImportParams) (Import, error)

Marks an import done with its document. Finishing it again with the same document changes nothing; a failed import stays failed.

func (*Queries) FinishMessage

func (q *Queries) FinishMessage(ctx context.Context, arg FinishMessageParams) (FinishMessageRow, error)

Ends a streaming answer with what it said and what it cost.

func (*Queries) GetAccount

func (q *Queries) GetAccount(ctx context.Context, arg GetAccountParams) (GetAccountRow, error)

func (*Queries) GetAnnotation

func (q *Queries) GetAnnotation(ctx context.Context, arg GetAnnotationParams) (Annotation, error)

func (*Queries) GetCachedEmbeddings

func (q *Queries) GetCachedEmbeddings(ctx context.Context, arg GetCachedEmbeddingsParams) ([]GetCachedEmbeddingsRow, error)

func (*Queries) GetConversation

func (q *Queries) GetConversation(ctx context.Context, arg GetConversationParams) (GetConversationRow, error)

func (*Queries) GetDocument

func (q *Queries) GetDocument(ctx context.Context, arg GetDocumentParams) (GetDocumentRow, error)

The document, with the warnings of the extraction it was made from. A web page's source is its URL; a PDF's, its file (source.pdf in the IR).

func (*Queries) GetIdentity

func (q *Queries) GetIdentity(ctx context.Context, arg GetIdentityParams) (UserIdentity, error)

func (*Queries) GetImport

func (q *Queries) GetImport(ctx context.Context, arg GetImportParams) (Import, error)

func (*Queries) GetIndexState

func (q *Queries) GetIndexState(ctx context.Context, arg GetIndexStateParams) (GetIndexStateRow, error)

func (*Queries) GetSession

func (q *Queries) GetSession(ctx context.Context, arg GetSessionParams) (GetSessionRow, error)

A session past its absolute limit, or unused for longer than the idle limit, is no session. Stale says its last use is older than touch_seconds, by the database's clock, which wrote it.

func (*Queries) GetUser

func (q *Queries) GetUser(ctx context.Context, id uuid.UUID) (User, error)

func (*Queries) GetUserByEmail

func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error)

func (*Queries) InsertChunk

func (q *Queries) InsertChunk(ctx context.Context, arg InsertChunkParams) error

Headings and prose are read as English, code as it is; idents is a tsvector literal of the identifier tokens, weighted A.

func (*Queries) InsertMessage

func (q *Queries) InsertMessage(ctx context.Context, arg InsertMessageParams) (InsertMessageRow, error)

func (*Queries) LatestImportForDocument

func (q *Queries) LatestImportForDocument(ctx context.Context, arg LatestImportForDocumentParams) (Import, error)

func (*Queries) ListAnnotations

func (q *Queries) ListAnnotations(ctx context.Context, arg ListAnnotationsParams) ([]Annotation, error)

Every query here is scoped by owner_id; TestOwnedQueriesAreScoped checks it.

func (*Queries) ListConversations

func (q *Queries) ListConversations(ctx context.Context, arg ListConversationsParams) ([]ListConversationsRow, error)

The owner's conversations, most recently active first, after the (updated_at, id) cursor.

func (*Queries) ListDocuments

func (q *Queries) ListDocuments(ctx context.Context, arg ListDocumentsParams) ([]ListDocumentsRow, error)

The owner's documents, newest first, after the (created_at, id) cursor.

func (*Queries) ListMessages

func (q *Queries) ListMessages(ctx context.Context, arg ListMessagesParams) ([]ListMessagesRow, error)

A conversation's messages in order. An answer still streaming after longer than any answer runs failed with its process.

func (*Queries) LockConversation

func (q *Queries) LockConversation(ctx context.Context, arg LockConversationParams) (uuid.UUID, error)

Holds the conversation until the transaction ends, so two answers can't both start in it.

func (*Queries) LockDocumentContent

func (q *Queries) LockDocumentContent(ctx context.Context, arg LockDocumentContentParams) ([]byte, error)

The document's content, locked until the transaction ends, so annotations are checked against the text a save cannot change meanwhile.

func (*Queries) LockOwner

func (q *Queries) LockOwner(ctx context.Context, ownerID uuid.UUID) error

Holds the owner's quota lock until the transaction ends, so two imports can't both pass a check that only one fits under.

func (*Queries) MarkIndexed

func (q *Queries) MarkIndexed(ctx context.Context, arg MarkIndexedParams) error

func (*Queries) NewestSnapshot

func (q *Queries) NewestSnapshot(ctx context.Context, sourceID uuid.UUID) (NewestSnapshotRow, error)

The newest snapshot of a web source, whose body Postgres holds.

func (*Queries) PutCachedEmbedding

func (q *Queries) PutCachedEmbedding(ctx context.Context, arg PutCachedEmbeddingParams) error

func (*Queries) QuotaUsage

func (q *Queries) QuotaUsage(ctx context.Context, arg QuotaUsageParams) (QuotaUsageRow, error)

What counts against the owner's quotas: imports started within the window and how many seconds until the oldest of them leaves it; and documents, with the imports still under way, which may each make one.

func (*Queries) ResolveDocuments

func (q *Queries) ResolveDocuments(ctx context.Context, arg ResolveDocumentsParams) ([]ResolveDocumentsRow, error)

For each canonical URL, the owner's document for it, matched as FindOwnerDocumentForURL matches one URL. URLs without one are left out.

func (*Queries) SaveDocument

func (q *Queries) SaveDocument(ctx context.Context, arg SaveDocumentParams) (int32, error)

Replaces the content if the document is still at version, and bumps it.

func (*Queries) SaveExtraction

func (q *Queries) SaveExtraction(ctx context.Context, arg SaveExtractionParams) (SaveExtractionRow, error)

Inserts an extraction, or returns the stored one for the same snapshot and extractor version, with its IR.

func (*Queries) SavePDFSnapshot

func (q *Queries) SavePDFSnapshot(ctx context.Context, arg SavePDFSnapshotParams) (uuid.UUID, error)

The snapshot of a PDF source: its blob, not its body. The no-op update makes RETURNING see an existing row.

func (*Queries) SaveSnapshot

func (q *Queries) SaveSnapshot(ctx context.Context, arg SaveSnapshotParams) (uuid.UUID, error)

Inserts a snapshot, or returns the one the source already has with the same body. The no-op update makes RETURNING see that row.

func (*Queries) SearchChunks

func (q *Queries) SearchChunks(ctx context.Context, arg SearchChunksParams) ([]SearchChunksRow, error)

Every query on chunks is scoped by owner_id; TestOwnedQueriesAreScoped checks it. Hybrid search over one user's chunks (docs/adr/0011-retrieval.md): the top 50 by words and the top 50 by meaning, each read through the owner's rows alone, merged by reciprocal rank fusion. A null query vector leaves the meaning half out; use_words false leaves the words half out.

Chunks that tie, as the copies of one page in two documents do, are ordered by document, oldest first (ids are UUIDv7), then by place in the document, in every ranking and the last one. Not by chunk id: indexing a document again makes new ones, which would put its chunks after another document's. So the order never rests on the query plan or on an edit (docs/adr/0011-retrieval.md).

func (*Queries) SetIdentityLogin

func (q *Queries) SetIdentityLogin(ctx context.Context, arg SetIdentityLoginParams) error

func (*Queries) SetImportPDFPages

func (q *Queries) SetImportPDFPages(ctx context.Context, arg SetImportPDFPagesParams) error

Records the page count pdftext read in a PDF import's file.

func (*Queries) SetImportStatus

func (q *Queries) SetImportStatus(ctx context.Context, arg SetImportStatusParams) (Import, error)

Moves an import that has not finished to a working status.

func (*Queries) TouchConversation

func (q *Queries) TouchConversation(ctx context.Context, arg TouchConversationParams) error

Marks the conversation active now, and titles it with its first question.

func (*Queries) TouchSession

func (q *Queries) TouchSession(ctx context.Context, tokenHash []byte) error

func (*Queries) TouchSource

func (q *Queries) TouchSource(ctx context.Context, arg TouchSourceParams) error

func (*Queries) UpdateAnnotation

func (q *Queries) UpdateAnnotation(ctx context.Context, arg UpdateAnnotationParams) (Annotation, error)

Replaces block, selector and note if the annotation is still at version, and bumps it.

func (*Queries) UpsertPDFSource

func (q *Queries) UpsertPDFSource(ctx context.Context, arg UpsertPDFSourceParams) (uuid.UUID, error)

The owner's source for the PDF with this SHA-256, created the first time. A PDF's source is never shared (docs/adr/0013-pdf-import.md).

func (*Queries) UpsertSource

func (q *Queries) UpsertSource(ctx context.Context, arg UpsertSourceParams) (UpsertSourceRow, error)

func (*Queries) WithTx

func (q *Queries) WithTx(tx pgx.Tx) *Queries

type QuotaUsageParams

type QuotaUsageParams struct {
	WindowSeconds float64
	OwnerID       uuid.UUID
}

type QuotaUsageRow

type QuotaUsageRow struct {
	RecentImports            int32
	SecondsUntilOldestLeaves float64
	Documents                int32
}

type ResolveDocumentsParams

type ResolveDocumentsParams struct {
	Urls    []string
	OwnerID uuid.UUID
}

type ResolveDocumentsRow

type ResolveDocumentsRow struct {
	URL        string
	DocumentID uuid.UUID
}

type SaveDocumentParams

type SaveDocumentParams struct {
	Content []byte
	OwnerID uuid.UUID
	ID      uuid.UUID
	Version int32
}

type SaveExtractionParams

type SaveExtractionParams struct {
	SnapshotID       uuid.UUID
	ExtractorName    string
	ExtractorVersion string
	IRVersion        int32
	IR               []byte
}

type SaveExtractionRow

type SaveExtractionRow struct {
	ID uuid.UUID
	IR []byte
}

type SavePDFSnapshotParams

type SavePDFSnapshotParams struct {
	SourceID   uuid.UUID
	BodySHA256 string
	BlobKey    string
	FetchedAt  time.Time
}

type SaveSnapshotParams

type SaveSnapshotParams struct {
	SourceID    uuid.UUID
	BodySHA256  string
	BodyGzip    []byte
	ContentType string
	FetchedAt   time.Time
}

type SearchChunksParams

type SearchChunksParams struct {
	OwnerID     uuid.UUID
	MaxResults  int32
	QueryVector *pgvector.HalfVector
	Q           string
	IdentQuery  string
	UseWords    bool
	DocumentID  uuid.NullUUID
	Model       string
	K           int32
}

type SearchChunksRow

type SearchChunksRow struct {
	ID          uuid.UUID
	DocumentID  uuid.UUID
	Title       string
	BlockIDs    []string
	BlockTexts  []string
	HeadingPath []string
	Kind        string
	Score       float64
	WordsRank   int32
	MeaningRank int32
	Distance    float64
	Snippet     string
}

type SetIdentityLoginParams

type SetIdentityLoginParams struct {
	Provider       string
	ProviderUserID string
	Login          string
}

type SetImportPDFPagesParams

type SetImportPDFPagesParams struct {
	PdfPages pgtype.Int4
	OwnerID  uuid.UUID
	ID       uuid.UUID
}

type SetImportStatusParams

type SetImportStatusParams struct {
	Status  string
	OwnerID uuid.UUID
	ID      uuid.UUID
}

type TouchConversationParams

type TouchConversationParams struct {
	Title   string
	OwnerID uuid.UUID
	ID      uuid.UUID
}

type TouchSourceParams

type TouchSourceParams struct {
	FetchedAt time.Time
	ID        uuid.UUID
}

type UpdateAnnotationParams

type UpdateAnnotationParams struct {
	BlockID  string
	Selector []byte
	Note     pgtype.Text
	OwnerID  uuid.UUID
	ID       uuid.UUID
	Version  int32
}

type UpsertPDFSourceParams

type UpsertPDFSourceParams struct {
	OwnerID     uuid.UUID
	PDFSHA256   string
	ConvertedAt time.Time
}

type UpsertSourceParams

type UpsertSourceParams struct {
	CanonicalURL  string
	FinalURL      string
	ETag          string
	LastModified  string
	LastFetchedAt time.Time
}

type UpsertSourceRow

type UpsertSourceRow struct {
	ID            uuid.UUID
	CanonicalURL  string
	FinalURL      string
	ETag          string
	LastModified  string
	LastFetchedAt time.Time
}

type User

type User struct {
	ID          uuid.UUID
	Email       string
	DisplayName string
	CreatedAt   time.Time
}

type UserIdentity

type UserIdentity struct {
	Provider       string
	ProviderUserID string
	UserID         uuid.UUID
	Login          string
	CreatedAt      time.Time
}

Jump to

Keyboard shortcuts

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