engine

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT 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 engine executes bounded parallel map, filter, and tree-reduce operations over shard items using an LLM Completer.

Index

Constants

View Source
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 Completer

type Completer interface {
	Complete(ctx context.Context, req llm.Request) (llm.Response, error)
}

Completer is the minimal LLM interface required by Engine.

type Engine

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

Engine orchestrates parallel LLM shard execution.

func New

func New(c Completer) *Engine

New constructs an Engine backed by c.

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

func (e *Engine) Map(ctx context.Context, items []shard.Item, opts Options) (MapResult, error)

Map applies opts.MapPrompt across items concurrently and returns ordered results.

func (*Engine) MapReduce

func (e *Engine) MapReduce(ctx context.Context, items []shard.Item, opts Options) (MapReduceResult, error)

MapReduce runs map across items in parallel and synthesizes outputs via Reduce.

func (*Engine) Reduce

func (e *Engine) Reduce(ctx context.Context, inputs []string, opts Options) (MapReduceResult, error)

Reduce synthesizes inputs using opts.ReducePrompt, applying tree-reduction automatically if inputs exceed opts.MaxReduceTokens.

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.

Jump to

Keyboard shortcuts

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