embeddings

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache provides content-hash-based caching for embeddings

func NewCache

func NewCache(dir string, provider string, logger *slog.Logger) (*Cache, error)

NewCache creates a new embedding cache for a specific provider. The provider name is used to segregate cache entries by provider.

func (*Cache) Clear

func (c *Cache) Clear() error

Clear removes all cached embeddings for this provider

func (*Cache) ClearAll added in v0.14.0

func (c *Cache) ClearAll() error

ClearAll removes all cached embeddings for all providers

func (*Cache) Delete

func (c *Cache) Delete(hash string) error

Delete removes an embedding from cache

func (*Cache) Get

func (c *Cache) Get(hash string) ([]float32, bool)

Get retrieves an embedding from cache by content hash Returns the embedding and true if found, nil and false otherwise

func (*Cache) Set

func (c *Cache) Set(hash string, embedding []float32) error

Set stores an embedding in cache by content hash

type EmbeddingResult

type EmbeddingResult struct {
	Text      string    `json:"text"`
	Embedding []float32 `json:"embedding"`
	Model     string    `json:"model"`
}

EmbeddingResult contains the result of an embedding operation

type Provider

type Provider interface {
	// Embed generates an embedding vector for a single text
	Embed(ctx context.Context, text string) ([]float32, error)

	// EmbedBatch generates embedding vectors for multiple texts
	// This is more efficient than calling Embed multiple times
	EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)

	// Dimensions returns the number of dimensions in the embedding vector
	Dimensions() int

	// Model returns the model name being used
	Model() string

	// Name returns the provider identifier (e.g., "openai", "voyage", "gemini")
	Name() string

	// DefaultRateLimit returns the default rate limit in requests per minute
	// Used when rate limit headers are unavailable from the API
	DefaultRateLimit() int
}

Provider defines the interface for embedding generation

type ProviderConfig added in v0.14.0

type ProviderConfig struct {
	// API credentials
	APIKey string

	// Model selection
	Model string

	// Vector dimensions (must match model)
	Dimensions int
}

ProviderConfig contains shared configuration for all embedding providers. Provider-specific implementations extract the fields they need.

type ProviderFactory added in v0.14.0

type ProviderFactory func(config ProviderConfig, logger *slog.Logger) (Provider, error)

ProviderFactory creates a Provider instance from configuration. Each provider registers its factory function during initialization.

type Registry added in v0.14.0

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

Registry manages all available embedding providers. It provides thread-safe registration, lookup, and listing operations.

func GlobalRegistry added in v0.14.0

func GlobalRegistry() *Registry

GlobalRegistry returns the singleton registry instance

func NewRegistry added in v0.14.0

func NewRegistry() *Registry

NewRegistry creates a new provider registry

func (*Registry) Get added in v0.14.0

func (r *Registry) Get(name string) (ProviderFactory, error)

Get retrieves a provider factory by name. Returns error if the provider is not found.

func (*Registry) List added in v0.14.0

func (r *Registry) List() []string

List returns the names of all registered providers. The returned slice is a copy and safe for concurrent use.

func (*Registry) Register added in v0.14.0

func (r *Registry) Register(name string, factory ProviderFactory)

Register adds a provider factory to the registry. Provider implementations call this in their init() functions. If a provider with the same name already exists, it will be replaced.

Directories

Path Synopsis
Package providers imports all embedding providers to trigger their registration.
Package providers imports all embedding providers to trigger their registration.

Jump to

Keyboard shortcuts

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