Documentation
¶
Index ¶
- Variables
- type CachedProvider
- func (c *CachedProvider) CacheStats() (size int, capacity int)
- func (c *CachedProvider) ClearCache()
- func (c *CachedProvider) Close() error
- func (c *CachedProvider) Dimensions() int
- func (c *CachedProvider) Embed(ctx context.Context, text string) ([]float32, error)
- func (c *CachedProvider) EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)
- type EmbeddingRequest
- type EmbeddingResponse
- type IrisClient
- type Provider
- type UsageInfo
Constants ¶
This section is empty.
Variables ¶
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) EmbedBatch ¶
EmbedBatch generates embeddings for multiple texts, using cache where available. Non-cached texts are fetched from the underlying provider in a single batch.
type EmbeddingRequest ¶
type EmbeddingRequest struct {
Provider string `json:"provider"` // e.g., "openai", "anthropic", "cohere"
Model string `json:"model"` // e.g., "text-embedding-3-small"
Input []string `json:"input"` // Text inputs to embed
}
EmbeddingRequest represents a request to generate embeddings.
type EmbeddingResponse ¶
type EmbeddingResponse struct {
Embeddings [][]float32 `json:"embeddings"` // One embedding per input
Model string `json:"model"` // Model used
Usage UsageInfo `json:"usage"` // Token usage information
}
EmbeddingResponse represents the response from an embedding request.
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) EmbedBatch ¶
EmbedBatch generates embeddings for multiple texts in a single call.
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.