embedding

package
v0.3.7-alpha Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: Apache-2.0 Imports: 2 Imported by: 30

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetImplSpecificOptions added in v0.3.6

func GetImplSpecificOptions[T any](base *T, opts ...Option) *T

GetImplSpecificOptions extract the implementation specific options from Option list, optionally providing a base options with default values. e.g.

myOption := &MyOption{
	Field1: "default_value",
}

myOption := model.GetImplSpecificOptions(myOption, opts...)

Types

type CallbackInput

type CallbackInput struct {
	// Texts is the texts to be embedded.
	Texts []string
	// Config is the config for the embedding.
	Config *Config
	// Extra is the extra information for the callback.
	Extra map[string]any
}

CallbackInput is the input for the embedding callback.

func ConvCallbackInput

func ConvCallbackInput(src callbacks.CallbackInput) *CallbackInput

ConvCallbackInput converts the callback input to the embedding callback input.

type CallbackOutput

type CallbackOutput struct {
	// Embeddings is the embeddings.
	Embeddings [][]float64
	// Config is the config for creating the embedding.
	Config *Config
	// TokenUsage is the token usage for the embedding.
	TokenUsage *TokenUsage
	// Extra is the extra information for the callback.
	Extra map[string]any
}

CallbackOutput is the output for the embedding callback.

func ConvCallbackOutput

func ConvCallbackOutput(src callbacks.CallbackOutput) *CallbackOutput

ConvCallbackOutput converts the callback output to the embedding callback output.

type ComponentExtra

type ComponentExtra struct {
	// Config is the config for the embedding.
	Config *Config
	// TokenUsage is the token usage for the embedding.
	TokenUsage *TokenUsage
}

ComponentExtra is the extra information for the embedding.

type Config

type Config struct {
	// Model is the model name.
	Model string
	// EncodingFormat is the encoding format.
	EncodingFormat string
}

Config is the config for the embedding.

type Embedder

type Embedder interface {
	EmbedStrings(ctx context.Context, texts []string, opts ...Option) ([][]float64, error) // invoke
}

type Option

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

Option is the call option for Embedder component.

func WithModel

func WithModel(model string) Option

WithModel is the option to set the model for the embedding.

func WrapImplSpecificOptFn added in v0.3.6

func WrapImplSpecificOptFn[T any](optFn func(*T)) Option

WrapImplSpecificOptFn is the option to wrap the implementation specific option function.

type Options

type Options struct {
	// Model is the model name for the embedding.
	Model *string
}

Options is the options for the embedding.

func GetCommonOptions

func GetCommonOptions(base *Options, opts ...Option) *Options

GetCommonOptions extract embedding Options from Option list, optionally providing a base Options with default values. eg.

defaultModelName := "default_model"
embeddingOption := &embedding.Options{
	Model: &defaultModelName,
}
embeddingOption := embedding.GetCommonOptions(embeddingOption, opts...)

type TokenUsage

type TokenUsage struct {
	// PromptTokens is the number of prompt tokens.
	PromptTokens int
	// CompletionTokens is the number of completion tokens.
	CompletionTokens int
	// TotalTokens is the total number of tokens.
	TotalTokens int
}

TokenUsage is the token usage for the embedding.

Jump to

Keyboard shortcuts

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