embeddings

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultDashScopeBaseURL = "https://dashscope.aliyuncs.com"
	DashScopeEmbeddingPath  = "/api/v1/services/embeddings/multimodal-embedding/multimodal-embedding"
)
View Source
const (
	TypeText       = "text"
	TypeMultimodal = "multimodal"
)

Variables

This section is empty.

Functions

func CollectEmbeddingVectors

func CollectEmbeddingVectors(ctx context.Context, service *models.Service) (map[string]int, models.GetResponse, models.GetResponse, bool, error)

CollectEmbeddingVectors gathers embedding model dimensions and defaults.

Types

type DashScopeEmbedder

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

func NewDashScopeEmbedder

func NewDashScopeEmbedder(log *slog.Logger, apiKey, baseURL, model string, timeout time.Duration) *DashScopeEmbedder

func (*DashScopeEmbedder) Embed

func (e *DashScopeEmbedder) Embed(ctx context.Context, text string, imageURL string, videoURL string) ([]float32, DashScopeUsage, error)

type DashScopeUsage

type DashScopeUsage struct {
	InputTokens int `json:"input_tokens"`
	ImageTokens int `json:"image_tokens"`
	ImageCount  int `json:"image_count,omitempty"`
	Duration    int `json:"duration,omitempty"`
}

type Embedder

type Embedder interface {
	Embed(ctx context.Context, input string) ([]float32, error)
	Dimensions() int
}

type Input

type Input struct {
	Text     string
	ImageURL string
	VideoURL string
}

type OpenAIEmbedder

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

func NewOpenAIEmbedder

func NewOpenAIEmbedder(log *slog.Logger, apiKey, baseURL, model string, dims int, timeout time.Duration) (*OpenAIEmbedder, error)

func (*OpenAIEmbedder) Dimensions

func (e *OpenAIEmbedder) Dimensions() int

func (*OpenAIEmbedder) Embed

func (e *OpenAIEmbedder) Embed(ctx context.Context, input string) ([]float32, error)

type Request

type Request struct {
	Type       string
	Provider   string
	Model      string
	Dimensions int
	Input      Input
}

type Resolver

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

func NewResolver

func NewResolver(log *slog.Logger, modelsService *models.Service, queries *sqlc.Queries, timeout time.Duration) *Resolver

func (*Resolver) Embed

func (r *Resolver) Embed(ctx context.Context, req Request) (Result, error)

type ResolverTextEmbedder

type ResolverTextEmbedder struct {
	Resolver *Resolver
	ModelID  string
	Dims     int
}

ResolverTextEmbedder adapts Resolver to the Embedder interface for text embeddings.

func (*ResolverTextEmbedder) Dimensions

func (e *ResolverTextEmbedder) Dimensions() int

func (*ResolverTextEmbedder) Embed

func (e *ResolverTextEmbedder) Embed(ctx context.Context, input string) ([]float32, error)

type Result

type Result struct {
	Type       string
	Provider   string
	Model      string
	Dimensions int
	Embedding  []float32
	Usage      Usage
}

type Usage

type Usage struct {
	InputTokens int
	ImageTokens int
	Duration    int
}

Jump to

Keyboard shortcuts

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