embedding

package
v0.0.0-...-683b713 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package embedding defines utilities for embedding text with various providers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Batcher

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

Batcher is an `Embedder` that batches input data before embedding it.

func (*Batcher) Embed

func (b *Batcher) Embed(ctx context.Context, purpose Purpose, texts []string) (*Embeddings, error)

type DataType

type DataType int

DataType is the underlying datatype of an embedding.

const (
	DataTypeUnknown DataType = iota
	DataTypeF32
)

Supported data types.

func (DataType) String

func (dt DataType) String() string

type Embedder

type Embedder interface {
	// Embed embeds the given texts and returns their embeddings.
	Embed(ctx context.Context, purpose Purpose, texts []string) (*Embeddings, error)
}

An Embedder is anything that can embed text in batches.

func ConstructEmbedder

func ConstructEmbedder(model Model) (Embedder, error)

ConstructEmbedder constructs an embedder for the given model.

type EmbedderFn

type EmbedderFn func(context.Context, Purpose, []string) (*Embeddings, error)

EmbedderFn is a function that embeds text in batches.

func (EmbedderFn) Embed

func (f EmbedderFn) Embed(
	ctx context.Context,
	purpose Purpose,
	texts []string,
) (*Embeddings, error)

type Embeddings

type Embeddings struct {
	Dims int
	F32  []float32
}

Embeddings is a collection of embeddings with a given dimensionality.

func (*Embeddings) At

func (e *Embeddings) At(i int) ([]float32, error)

At returns the embedding at the given index.

func (*Embeddings) DataType

func (e *Embeddings) DataType() DataType

DataType returns the underlying data type of the embeddings.

func (*Embeddings) IterF32

func (e *Embeddings) IterF32() (iter.Seq[[]float32], error)

IterF32 iterates over the f32 embeddings in batches of Dims.

type Limiter

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

Limiter is an `Embedder` that limits the rate of requests to an inner `Embedder`.

func (*Limiter) Embed

func (l *Limiter) Embed(ctx context.Context, purpose Purpose, texts []string) (*Embeddings, error)

type Model

type Model string

Model is an enumeration over the models we support.

const (
	ModelVoyageLarge2Instruct Model = "voyage-large-2-instruct"
)

Supported models.

func (Model) DataType

func (m Model) DataType() DataType

DataType returns the underlying datatype of the model's embeddings.

func (Model) Dims

func (m Model) Dims() int

Dims returns the dimensionality of the returned embeddings from the model.

func (Model) MaxBatchSize

func (m Model) MaxBatchSize() int

MaxBatchSize returns the maximum batch size for the model.

func (Model) MaxReqsPerSec

func (m Model) MaxReqsPerSec() int

MaxReqsPerSec returns the rate limit for the model, as max requests per second.

func (Model) String

func (m Model) String() string

type Purpose

type Purpose int

Purpose is an enumeration over the purposes for which embeddings can be used.

const (
	PurposeUnknown Purpose = iota
	PurposeQuery
	PurposeIndex
)

Supported purposes.

Jump to

Keyboard shortcuts

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