embed

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProviderOpenAI           = "openai"
	ProviderOllama           = "ollama"
	ProviderLlamaCpp         = "llamacpp"
	ProviderOpenAICompatible = "openai_compatible"

	DefaultOpenAIBaseURL       = "https://api.openai.com/v1"
	DefaultOllamaBaseURL       = "http://127.0.0.1:11434"
	DefaultLlamaCppBaseURL     = "http://127.0.0.1:8080/v1"
	DefaultOpenAIModel         = "text-embedding-3-small"
	DefaultLocalEmbeddingModel = "nomic-embed-text"
	DefaultBatchSize           = 64
	DefaultMaxInputChars       = 12000
	DefaultRequestTimeout      = 2 * time.Minute
	DefaultProbeTimeout        = 2 * time.Second
)

Variables

This section is empty.

Functions

func IsRateLimitError

func IsRateLimitError(err error) bool

Types

type CheckResult

type CheckResult struct {
	Provider string
	Model    string
	BaseURL  string
	Status   string
	Warning  string
	Probed   bool
}

func CheckProvider

func CheckProvider(ctx context.Context, cfg Config) CheckResult

type Config

type Config struct {
	Provider       string
	Model          string
	BaseURL        string
	APIKeyEnv      string
	RequestTimeout string
	MaxInputChars  int
	Dimensions     int
	UserAgent      string
}

type EmbeddingBatch

type EmbeddingBatch struct {
	Model      string
	Dimensions int
	Vectors    [][]float32
	Vectors64  [][]float64
}

type HTTPError

type HTTPError struct {
	StatusCode int
	Body       string
	Header     http.Header
}

func (*HTTPError) Error

func (e *HTTPError) Error() string

type Option

type Option func(*providerOptions)

func WithAPIKey added in v0.5.3

func WithAPIKey(apiKey string) Option

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

func WithRequestTimeout

func WithRequestTimeout(timeout time.Duration) Option

func WithUserAgent added in v0.5.3

func WithUserAgent(userAgent string) Option

type Provider

type Provider interface {
	Embed(ctx context.Context, inputs []string) (EmbeddingBatch, error)
}

func NewProvider

func NewProvider(cfg Config, opts ...Option) (Provider, error)

Jump to

Keyboard shortcuts

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