embedding

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyInput     = errors.New("empty input text")
	ErrBatchTooLarge  = errors.New("batch size exceeds limit")
	ErrProviderFailed = errors.New("embedding provider failed")
)

Common errors returned by embedding providers.

Functions

This section is empty.

Types

type CachedProvider

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

CachedProvider wraps a Provider with an LRU cache for embeddings. This reduces redundant API calls for repeated queries.

func NewCachedProvider

func NewCachedProvider(provider Provider, cacheSize int) (*CachedProvider, error)

NewCachedProvider creates a new cached embedding provider. cacheSize specifies the maximum number of embeddings to cache.

func (*CachedProvider) CacheStats

func (c *CachedProvider) CacheStats() (size int, capacity int)

CacheStats returns cache statistics.

func (*CachedProvider) ClearCache

func (c *CachedProvider) ClearCache()

ClearCache removes all entries from the cache.

func (*CachedProvider) Close

func (c *CachedProvider) Close() error

Close closes the underlying provider.

func (*CachedProvider) Dimensions

func (c *CachedProvider) Dimensions() int

Dimensions returns the embedding dimensions from the underlying provider.

func (*CachedProvider) Embed

func (c *CachedProvider) Embed(ctx context.Context, text string) ([]float32, error)

Embed generates an embedding, using the cache if available.

func (*CachedProvider) EmbedBatch

func (c *CachedProvider) EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)

EmbedBatch generates embeddings for multiple texts, using cache where available. Non-cached texts are fetched from the underlying provider in a single batch.

type IrisClient

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

IrisClient implements the Provider interface using the iris SDK.

func NewIrisClient

func NewIrisClient(cfg *config.Config) (*IrisClient, error)

NewIrisClient creates a new Iris embedding client using the iris SDK.

func (*IrisClient) Close

func (c *IrisClient) Close() error

Close releases resources. For iris SDK, this is a no-op.

func (*IrisClient) Dimensions

func (c *IrisClient) Dimensions() int

Dimensions returns the configured embedding dimensions.

func (*IrisClient) Embed

func (c *IrisClient) Embed(ctx context.Context, text string) ([]float32, error)

Embed generates an embedding for a single text input.

func (*IrisClient) EmbedBatch

func (c *IrisClient) EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)

EmbedBatch generates embeddings for multiple texts, automatically splitting inputs that exceed the configured batch size into sub-batches and concatenating the results. A document that produces more chunks than batch_size no longer fails the whole embed — it is processed in batch_size-sized provider calls.

type Provider

type Provider interface {
	// Embed generates an embedding vector for a single text input.
	// Returns a float32 slice of the configured dimensions.
	Embed(ctx context.Context, text string) ([]float32, error)

	// EmbedBatch generates embeddings for multiple texts in a single call.
	// This is more efficient than calling Embed repeatedly for bulk operations.
	// Implementations should respect configured batch size limits.
	EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)

	// Dimensions returns the embedding vector dimensions.
	Dimensions() int

	// Close releases any resources held by the provider.
	Close() error
}

Provider defines the interface for embedding generation. Implementations may call external services (Iris, OpenAI) or provide local embeddings.

Jump to

Keyboard shortcuts

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