chains

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package chains provides common chain patterns for composing LangChain components.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LLMChain

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

LLMChain is the simplest chain: prompt -> model -> output. It implements Runnable[map[string]any, string].

func NewLLMChain

func NewLLMChain(llm llms.ChatModel, prompt *prompts.ChatPromptTemplate) *LLMChain

NewLLMChain creates a new LLMChain.

func (*LLMChain) Batch

func (c *LLMChain) Batch(ctx context.Context, inputs []map[string]any, opts ...core.Option) ([]string, error)

Batch runs the chain for multiple inputs.

func (*LLMChain) GetName

func (c *LLMChain) GetName() string

GetName returns the chain name.

func (*LLMChain) Invoke

func (c *LLMChain) Invoke(ctx context.Context, input map[string]any, opts ...core.Option) (string, error)

Invoke runs the chain.

func (*LLMChain) Stream

func (c *LLMChain) Stream(ctx context.Context, input map[string]any, opts ...core.Option) (*core.StreamIterator[string], error)

Stream runs the chain with streaming output.

type RetrievalQA

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

RetrievalQA combines a retriever with an LLM to answer questions. It retrieves relevant documents and uses them as context.

func NewRetrievalQA

func NewRetrievalQA(retriever retrievers.Retriever, llmChain *LLMChain) *RetrievalQA

NewRetrievalQA creates a new RetrievalQA chain.

func (*RetrievalQA) Batch

func (r *RetrievalQA) Batch(ctx context.Context, inputs []map[string]any, opts ...core.Option) ([]string, error)

Batch runs the chain for multiple inputs.

func (*RetrievalQA) GetName

func (r *RetrievalQA) GetName() string

GetName returns the chain name.

func (*RetrievalQA) Invoke

func (r *RetrievalQA) Invoke(ctx context.Context, input map[string]any, opts ...core.Option) (string, error)

Invoke retrieves documents and answers the query.

func (*RetrievalQA) Stream

func (r *RetrievalQA) Stream(ctx context.Context, input map[string]any, opts ...core.Option) (*core.StreamIterator[string], error)

Stream retrieves documents then streams the LLM response.

type StuffDocumentsChain

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

StuffDocumentsChain combines retrieved documents into a single context and passes them to an LLM chain.

func NewStuffDocumentsChain

func NewStuffDocumentsChain(llmChain *LLMChain) *StuffDocumentsChain

NewStuffDocumentsChain creates a chain that "stuffs" all documents into the prompt.

func (*StuffDocumentsChain) Batch

func (c *StuffDocumentsChain) Batch(ctx context.Context, inputs []map[string]any, opts ...core.Option) ([]string, error)

Batch runs the chain for multiple inputs.

func (*StuffDocumentsChain) GetName

func (c *StuffDocumentsChain) GetName() string

GetName returns the chain name.

func (*StuffDocumentsChain) Invoke

func (c *StuffDocumentsChain) Invoke(ctx context.Context, input map[string]any, opts ...core.Option) (string, error)

Invoke runs the chain with documents.

func (*StuffDocumentsChain) Stream

func (c *StuffDocumentsChain) Stream(ctx context.Context, input map[string]any, opts ...core.Option) (*core.StreamIterator[string], error)

Stream streams the chain output.

Jump to

Keyboard shortcuts

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