Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LLMChain ¶ added in v0.15.0
type LLMChain[T any] struct { LLM llms.Model Prompt prompts.PromptTemplate Parser schema.OutputParser[T] CallOptions []llms.CallOption }
LLMChain combines a prompt template, an LLM, and an output parser into a single callable unit. It renders the prompt, calls the LLM, and parses the output into a typed result.
func NewLLMChain ¶ added in v0.15.0
func NewLLMChain[T any](llm llms.Model, prompt prompts.PromptTemplate, opts ...LLMChainOption[T]) *LLMChain[T]
NewLLMChain creates a new LLMChain. If no parser is provided via options, a StringParser is used (only valid when T is string).
type LLMChainOption ¶ added in v0.15.0
LLMChainOption configures an LLMChain.
func WithLLMCallOptions ¶ added in v0.15.0
func WithLLMCallOptions[T any](opts ...llms.CallOption) LLMChainOption[T]
WithLLMCallOptions sets LLM call options (temperature, max tokens, etc.)
func WithOutputParser ¶ added in v0.15.0
func WithOutputParser[T any](parser schema.OutputParser[T]) LLMChainOption[T]
WithOutputParser sets a custom output parser for the chain.
type MapReduceChain ¶ added in v0.15.0
type MapReduceChain[In, Mid, Out any] struct { MapFunc func(ctx context.Context, input In) (Mid, error) ReduceFunc func(ctx context.Context, results []Mid) (Out, error) MaxConcurrency int Timeout time.Duration // per-task timeout (0 = no timeout) QuorumFraction float64 // e.g. 0.66 = return when 2/3 succeed }
MapReduceChain runs a map function concurrently over inputs, then reduces the collected results into a final output. Supports concurrency limits, per-task timeouts, and quorum-based early return.
func NewMapReduceChain ¶ added in v0.15.0
func NewMapReduceChain[In, Mid, Out any]( mapFn func(ctx context.Context, input In) (Mid, error), reduceFn func(ctx context.Context, results []Mid) (Out, error), opts ...MapReduceOption[In, Mid, Out], ) *MapReduceChain[In, Mid, Out]
type MapReduceOption ¶ added in v0.15.0
type MapReduceOption[In, Mid, Out any] func(*MapReduceChain[In, Mid, Out])
func WithMapTimeout ¶ added in v0.15.0
func WithMapTimeout[In, Mid, Out any](d time.Duration) MapReduceOption[In, Mid, Out]
WithMapTimeout sets a timeout for each individual map task.
func WithMaxConcurrency ¶ added in v0.15.0
func WithMaxConcurrency[In, Mid, Out any](n int) MapReduceOption[In, Mid, Out]
WithMaxConcurrency limits the number of map tasks running in parallel.
func WithQuorum ¶ added in v0.15.0
func WithQuorum[In, Mid, Out any](fraction float64) MapReduceOption[In, Mid, Out]
WithQuorum sets the fraction of map tasks that must succeed before the chain proceeds to the reduce step. For example, 0.66 means at least 2 out of 3 tasks must succeed.
type RetrievalQA ¶
type RetrievalQA struct {
Retriever schema.Retriever
LLM llms.Model
PromptBuilder func(query string, docs []schema.Document) (string, error)
}
func NewRetrievalQA ¶
func NewRetrievalQA(retriever schema.Retriever, llm llms.Model, opts ...RetrievalQAOption) RetrievalQA
type RetrievalQAOption ¶ added in v0.15.0
type RetrievalQAOption func(*RetrievalQA)
func WithPromptBuilder ¶ added in v0.15.0
func WithPromptBuilder(pb func(query string, docs []schema.Document) (string, error)) RetrievalQAOption
WithPromptBuilder allows passing a custom function to format the retrieved documents and query into a final string prompt.
type ValidatingRetrievalQA ¶ added in v0.2.0
type ValidatingRetrievalQA struct {
Retriever schema.Retriever
GeneratorLLM llms.Model
ValidatorLLM llms.Model
// contains filtered or unexported fields
}
ValidatingRetrievalQA validates the relevance of retrieved context before generation.
func NewValidatingRetrievalQA ¶ added in v0.2.0
func NewValidatingRetrievalQA(retriever schema.Retriever, generator llms.Model, opts ...ValidatingRetrievalQAOption) (ValidatingRetrievalQA, error)
NewValidatingRetrievalQA creates a new ValidatingRetrievalQA chain.
type ValidatingRetrievalQAOption ¶ added in v0.2.0
type ValidatingRetrievalQAOption func(*ValidatingRetrievalQA)
func WithLogger ¶ added in v0.2.0
func WithLogger(logger *slog.Logger) ValidatingRetrievalQAOption
func WithValidator ¶ added in v0.2.0
func WithValidator(llm llms.Model) ValidatingRetrievalQAOption