embedding

package
v0.3.1-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: Apache-2.0 Imports: 2 Imported by: 30

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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.

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