Documentation
¶
Overview ¶
Package engine executes bounded parallel map, filter, and tree-reduce operations over shard items using an LLM Completer.
Index ¶
- Constants
- type Completer
- type Engine
- func (e *Engine) Filter(ctx context.Context, items []shard.Item, opts Options) (FilterResult, error)
- func (e *Engine) Map(ctx context.Context, items []shard.Item, opts Options) (MapResult, error)
- func (e *Engine) MapReduce(ctx context.Context, items []shard.Item, opts Options) (MapReduceResult, error)
- func (e *Engine) Reduce(ctx context.Context, inputs []string, opts Options) (MapReduceResult, error)
- type ErrorPolicy
- type FilterMatch
- type FilterResult
- type MapReduceResult
- type MapResult
- type Options
- type ShardError
- type ShardResult
- type Stats
Constants ¶
const ( // DefaultConcurrency is the default number of parallel shard workers. DefaultConcurrency = 8 // MaxConcurrency is the upper ceiling on parallel shard workers. MaxConcurrency = 32 // DefaultRetries is the default retry count for transient shard errors. DefaultRetries = 2 // MaxRetries is the upper ceiling on per-shard retries. MaxRetries = 5 // DefaultShardTimeout is the default per-shard timeout. DefaultShardTimeout = 60 * time.Second // MaxShardTimeout is the upper ceiling on per-shard timeout. MaxShardTimeout = 10 * time.Minute // DefaultMaxReduceTokens triggers tree-reduction when map outputs exceed it. DefaultMaxReduceTokens = 48000 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine orchestrates parallel LLM shard execution.
func (*Engine) Filter ¶
func (e *Engine) Filter(ctx context.Context, items []shard.Item, opts Options) (FilterResult, error)
Filter evaluates opts.PredicatePrompt across items in parallel and returns matches.
func (*Engine) Map ¶
Map applies opts.MapPrompt across items concurrently and returns ordered results.
type ErrorPolicy ¶
type ErrorPolicy string
ErrorPolicy controls how shard failures affect a Map or MapReduce run.
const ( // BestEffort continues reducing successful shards and reports failures in Stats/Errors. BestEffort ErrorPolicy = "best_effort" // FailFast cancels all remaining shards on the first unrecoverable error. FailFast ErrorPolicy = "fail_fast" )
type FilterMatch ¶
type FilterMatch struct {
Index int `json:"index"`
Label string `json:"label"`
Reason string `json:"reason,omitempty"`
}
FilterMatch represents a single item that matched a Filter predicate.
type FilterResult ¶
type FilterResult struct {
Matches []FilterMatch `json:"matches"`
Stats Stats `json:"stats"`
Errors []ShardError `json:"errors,omitempty"`
}
FilterResult is returned by Filter.
type MapReduceResult ¶
type MapReduceResult struct {
Result string `json:"result"`
Raw []ShardResult `json:"raw,omitempty"`
Stats Stats `json:"stats"`
Errors []ShardError `json:"errors,omitempty"`
}
MapReduceResult is returned by MapReduce and Reduce.
type MapResult ¶
type MapResult struct {
Results []ShardResult `json:"results"`
Stats Stats `json:"stats"`
Errors []ShardError `json:"errors,omitempty"`
}
MapResult is returned by Map.
type Options ¶
type Options struct {
MapPrompt string
ReducePrompt string
PredicatePrompt string
MapModel string
ReduceModel string
Concurrency int
Retries int
ShardTimeout time.Duration
MaxReduceTokens int
OnError ErrorPolicy
JSONMode bool
}
Options configures a Map, Filter, Reduce, or MapReduce run.
type ShardError ¶
type ShardError struct {
Index int `json:"index"`
Label string `json:"label"`
Error string `json:"error"`
}
ShardError records a single failed shard.
type ShardResult ¶
type ShardResult struct {
Index int `json:"index"`
Label string `json:"label"`
Output string `json:"output,omitempty"`
Error string `json:"error,omitempty"`
}
ShardResult holds the output for a single mapped shard.
type Stats ¶
type Stats struct {
TotalItems int `json:"total_items"`
Succeeded int `json:"succeeded"`
Failed int `json:"failed"`
TreeReduceLevels int `json:"tree_reduce_levels"`
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
KeptOutOfContextTokens int `json:"kept_out_of_context_tokens"`
DurationMS int64 `json:"duration_ms"`
}
Stats summarizes execution metrics for an Engine run.