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 ¶
NewCache creates a new embedding cache for a specific provider. The provider name is used to segregate cache entries by provider.
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
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.