Documentation
¶
Overview ¶
Package memory ingests records, builds a prompt from them, and runs that prompt on many models at once.
A record is text plus a pointer. Media bytes and sockets stay outside. Compose a Pipe to decide what is stored, a View to decide what each model reads, and a Plan to run those models together or take the first result.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Album ¶
Album turns a record Ref into the image or video a vision model should see. The store keeps the pointer. The album keeps the bytes.
type Mem ¶
type Mem struct {
// contains filtered or unexported fields
}
Mem is an in-process store. cap is the most records kept per scope; zero keeps them all. The oldest record in that scope is dropped past the cap.
type Pipe ¶
type Pipe struct {
// contains filtered or unexported fields
}
Pipe is an ordered list of stages. Pipes are values: Then returns a new pipe.
type Plan ¶
type Plan struct {
Store Store
Scope string
View View
Messages []niro.Message
Targets []Target
Album Album
Race bool
}
Plan renders a view and runs every target. Race returns the first success and cancels the rest. Targets must stop when the context is canceled. When every target fails, Race returns each failure.
type Query ¶
type Query struct {
ID string
Scope string
AnyScope bool
Sources []string
Tags []string
Since time.Time
Until time.Time
Limit int
Match func(Record) bool
}
Query selects records. Zero fields match nothing extra: an empty Query matches only records whose Scope is empty.
Sources match if the record source is one of them. Tags match only when the record carries every listed tag. Until is exclusive. Limit is applied by the store after matching, keeping the newest records. Limit is not part of Allows.
type Record ¶
type Record struct {
ID string
Scope string
Source string
Body string
Ref string
Tags []string
Meta map[string]string
At time.Time
}
Record is one thing worth remembering. Ref points at something stored elsewhere (a URL, an id). A target with See resolves Ref through an Album into an image or video part. Tags and Meta are for the caller; this package does not interpret them.
type Reel ¶
type Reel struct {
// contains filtered or unexported fields
}
Reel is an in-process album. cap is the most frames kept; zero keeps them all. Putting the same ref again replaces that frame and makes it the newest.
type Result ¶
type Result struct {
Name string
Model string
Prompt string
Text string
Usage niro.Usage
Err error
}
Result is one target's output. Prompt is the system prompt that was sent. Err is set when that model failed. Other targets still finish unless Race is set.
type Section ¶
Section is one block of a prompt. A nil Query is static: Write is called with no records. A nil Write renders records with Lines. An empty body is left out of the prompt.
type Stage ¶
Stage rewrites a batch of records before they are stored. Return no records to drop the batch. Return more than one record from a single input to fan an event out into several memories.
type Store ¶
type Store interface {
Put(ctx context.Context, rec Record) (Record, error)
Recall(ctx context.Context, q Query) ([]Record, error)
Forget(ctx context.Context, q Query) (int, error)
}
Store is the memory backend. Put with an existing ID in the same scope replaces that record. Recall returns matches oldest first. Forget removes matches.
type Target ¶
type Target struct {
Name string
Provider niro.Provider
Model string
Scope string
View *View
Messages []niro.Message
Tools []niro.Tool
ToolChoice niro.ToolChoice
Options niro.Options
Parts []niro.Part
See *Query
Album Album
Request func(prompt string, parts []niro.Part) *niro.Request
}
Target is one model in a plan. Scope and View, when set, replace the plan's scope and view for this model only. Messages, when non-nil, replace the plan messages. Parts are images or video attached to the user turn. See recalls records and resolves each Ref through the target Album, or the plan Album. Request, when set, builds the provider request from the rendered prompt and those parts. The other request fields are not used.