derive

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0 Imports: 17 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

Overview

Package derive turns raw transcript rows into the derived tables, exactly once per row.

Package derive turns parsed transcript events into derived facts such as cost.

Index

Constants

View Source
const ParserVersion = 5

ParserVersion is bumped whenever a parser or engine change requires re-deriving from raw data.

Variables

This section is empty.

Functions

func Cost

func Cost(u parse.Usage) (usd float64, estimated, unknown bool)

Cost prices one message in USD. estimated is true when the base price of the model, or of its closest known family member, was used for an unknown model or for Speed == "fast". unknown is true (and usd 0) only when no family matches at all.

func NormalizeModel

func NormalizeModel(m string) string

NormalizeModel strips a trailing "[...]" and a trailing "-YYYYMMDD".

func Snippet

func Snippet(raw []byte, role, q string) string

Snippet cuts a short plain-text excerpt for query q out of the raw line of a search hit (role "user" or "assistant"). Candidate texts: user = the prompt; assistant = each text block, then each tool call as "<tool> <summary>". The first candidate containing a query word (case-insensitive substring of any word of q) wins; the excerpt is a window of at most 160 runes around the match with "…" at cut ends and whitespace collapsed. No match: the start of the first candidate. Unparsable or empty input returns "".

Types

type Deriver

type Deriver struct {
	DB         *db.DB
	BatchLines int // raw rows per transaction, default 5000
	BatchBytes int // a chunk stops once this many raw bytes were read (at least one row), default 32 MiB
}

Deriver derives the pending raw rows of users.

func (*Deriver) DeriveUser

func (d *Deriver) DeriveUser(ctx context.Context, userID string) (rows int, err error)

DeriveUser derives everything pending for userID and returns the number of raw rows (lines + snapshots) processed.

func (*Deriver) DeriveUserSessions

func (d *Deriver) DeriveUserSessions(ctx context.Context, userID string) (rows int, sessions []string, err error)

DeriveUserSessions is DeriveUser that also returns the distinct session ids of the files that had rows.

func (*Deriver) Reset

func (d *Deriver) Reset(ctx context.Context, userID string) error

Reset deletes every derived row and cursor of the user (never raw data, never derive_state).

type Price

type Price struct{ Input, CacheWrite5m, CacheWrite1h, CacheRead, Output float64 }

Price is USD per million tokens.

type Worker

type Worker struct {
	D        *Deriver
	DB       *db.DB
	Sweep    time.Duration // default 60 s
	Debounce time.Duration // default 250 ms
	Workers  int           // default 2
	// OnReindexed (optional) is called after each finished Reindex with the raw rows re-derived.
	OnReindexed func(userID string, rows int)
	// contains filtered or unexported fields
}

Worker derives users whose raw data changed (LISTEN/NOTIFY plus a periodic sweep as safety net).

func (*Worker) Ready

func (w *Worker) Ready() <-chan struct{}

Ready is closed once LISTEN is active and the first sweep and the startup version check finished.

func (*Worker) Reindex

func (w *Worker) Reindex(ctx context.Context, userID string) error

Reindex discards and re-derives everything of one user from the raw data.

func (*Worker) ReindexAll

func (w *Worker) ReindexAll(ctx context.Context) error

ReindexAll reindexes all users, one after the other.

func (*Worker) Run

func (w *Worker) Run(ctx context.Context) error

Run blocks until ctx is done.

Directories

Path Synopsis
Package derivetest is test support for the derive engine: it stores raw data as ingest would and inspects the derived tables.
Package derivetest is test support for the derive engine: it stores raw data as ingest would and inspects the derived tables.
Package parse turns raw transcript lines and snapshots into typed events, leniently and without I/O.
Package parse turns raw transcript lines and snapshots into typed events, leniently and without I/O.

Jump to

Keyboard shortcuts

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