Documentation
¶
Index ¶
- func IsRegistered(name string) bool
- func ListProviders() []string
- func Register(name string, factory ProviderFactory)
- type Config
- type EmbeddingService
- type HuggingFaceConfig
- type HuggingFaceEmbeddings
- func (h *HuggingFaceEmbeddings) Close() error
- func (h *HuggingFaceEmbeddings) Dimensions() int
- func (h *HuggingFaceEmbeddings) Embed(ctx context.Context, text string) ([]float32, error)
- func (h *HuggingFaceEmbeddings) EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)
- func (h *HuggingFaceEmbeddings) ModelName() string
- type HuggingFaceTEIConfig
- type HuggingFaceTEIEmbeddings
- func (t *HuggingFaceTEIEmbeddings) Close() error
- func (t *HuggingFaceTEIEmbeddings) Dimensions() int
- func (t *HuggingFaceTEIEmbeddings) Embed(ctx context.Context, text string) ([]float32, error)
- func (t *HuggingFaceTEIEmbeddings) EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)
- func (t *HuggingFaceTEIEmbeddings) ModelName() string
- type OpenAIConfig
- type OpenAIEmbeddings
- func (o *OpenAIEmbeddings) Close() error
- func (o *OpenAIEmbeddings) Dimensions() int
- func (o *OpenAIEmbeddings) Embed(ctx context.Context, text string) ([]float32, error)
- func (o *OpenAIEmbeddings) EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)
- func (o *OpenAIEmbeddings) ModelName() string
- type ProviderFactory
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsRegistered ¶
IsRegistered checks if a provider is registered.
func ListProviders ¶
func ListProviders() []string
ListProviders returns a list of all registered embedding providers.
func Register ¶
func Register(name string, factory ProviderFactory)
Register adds a new embedding provider to the registry.
Types ¶
type Config ¶
type Config struct {
// Provider specifies which embedding service to use
// Supported values: "openai", "huggingface", "huggingface_tei"
Provider string `yaml:"provider" json:"provider"`
// OpenAI-specific configuration
OpenAI *OpenAIConfig `yaml:"openai,omitempty" json:"openai,omitempty"`
// HuggingFace-specific configuration
HuggingFace *HuggingFaceConfig `yaml:"huggingface,omitempty" json:"huggingface,omitempty"`
// HuggingFaceTEI-specific configuration (Text Embeddings Inference)
HuggingFaceTEI *HuggingFaceTEIConfig `yaml:"huggingface_tei,omitempty" json:"huggingface_tei,omitempty"`
}
Config holds configuration for embedding providers.
type EmbeddingService ¶
type EmbeddingService interface {
// Embed generates embeddings for a single text
Embed(ctx context.Context, text string) ([]float32, error)
// EmbedBatch generates embeddings for multiple texts
EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)
// Dimensions returns the dimension size of the embeddings
Dimensions() int
// ModelName returns the name of the embedding model
ModelName() string
// Close closes any resources held by the service
Close() error
}
EmbeddingService is the main interface for generating text embeddings.
func New ¶
func New(config Config) (EmbeddingService, error)
New creates a new EmbeddingService based on the provider specified in the config.
func NewHuggingFace ¶
func NewHuggingFace(config Config) (EmbeddingService, error)
NewHuggingFace creates a new HuggingFaceEmbeddings instance.
func NewHuggingFaceTEI ¶
func NewHuggingFaceTEI(config Config) (EmbeddingService, error)
NewHuggingFaceTEI creates a new HuggingFaceTEIEmbeddings instance.
func NewOpenAI ¶
func NewOpenAI(config Config) (EmbeddingService, error)
NewOpenAI creates a new OpenAIEmbeddings instance.
type HuggingFaceConfig ¶
type HuggingFaceConfig struct {
// APIKey for authentication (optional for public models)
APIKey string `yaml:"api_key,omitempty" json:"api_key,omitempty"`
// Model specifies which HuggingFace model to use
// Popular options:
// - "sentence-transformers/all-MiniLM-L6-v2" (384 dims, fast)
// - "BAAI/bge-small-en-v1.5" (384 dims)
// - "BAAI/bge-large-en-v1.5" (1024 dims)
// - "thenlper/gte-large" (1024 dims)
Model string `yaml:"model" json:"model"`
// Endpoint is the API endpoint (default: https://api-inference.huggingface.co)
Endpoint string `yaml:"endpoint,omitempty" json:"endpoint,omitempty"`
// WaitForModel waits if model is loading (default: true)
WaitForModel bool `yaml:"wait_for_model" json:"wait_for_model"`
// UseCache uses cached results (default: true)
UseCache bool `yaml:"use_cache" json:"use_cache"`
}
HuggingFaceConfig contains HuggingFace Inference API settings.
func (*HuggingFaceConfig) Validate ¶
func (hc *HuggingFaceConfig) Validate() error
Validate checks if HuggingFace configuration is valid.
type HuggingFaceEmbeddings ¶
type HuggingFaceEmbeddings struct {
// contains filtered or unexported fields
}
HuggingFaceEmbeddings implements EmbeddingService using HuggingFace Inference API.
func (*HuggingFaceEmbeddings) Close ¶
func (h *HuggingFaceEmbeddings) Close() error
Close closes any resources held by the service.
func (*HuggingFaceEmbeddings) Dimensions ¶
func (h *HuggingFaceEmbeddings) Dimensions() int
Dimensions returns the dimension size of the embeddings.
func (*HuggingFaceEmbeddings) EmbedBatch ¶
func (h *HuggingFaceEmbeddings) EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)
EmbedBatch generates embeddings for multiple texts.
func (*HuggingFaceEmbeddings) ModelName ¶
func (h *HuggingFaceEmbeddings) ModelName() string
ModelName returns the name of the embedding model.
type HuggingFaceTEIConfig ¶
type HuggingFaceTEIConfig struct {
// Endpoint is the TEI server URL (e.g., "http://localhost:8080")
Endpoint string `yaml:"endpoint" json:"endpoint"`
// Model name (informational, server determines actual model)
Model string `yaml:"model,omitempty" json:"model,omitempty"`
// Normalize returns normalized embeddings (default: true)
Normalize bool `yaml:"normalize" json:"normalize"`
}
HuggingFaceTEIConfig contains HuggingFace Text Embeddings Inference settings. TEI is a self-hosted, high-performance embedding server.
func (*HuggingFaceTEIConfig) Validate ¶
func (tc *HuggingFaceTEIConfig) Validate() error
Validate checks if HuggingFaceTEI configuration is valid.
type HuggingFaceTEIEmbeddings ¶
type HuggingFaceTEIEmbeddings struct {
// contains filtered or unexported fields
}
HuggingFaceTEIEmbeddings implements EmbeddingService using HuggingFace Text Embeddings Inference (TEI). TEI is a self-hosted, high-performance embedding server optimized for production use. See: https://github.com/huggingface/text-embeddings-inference
func (*HuggingFaceTEIEmbeddings) Close ¶
func (t *HuggingFaceTEIEmbeddings) Close() error
Close closes any resources held by the service.
func (*HuggingFaceTEIEmbeddings) Dimensions ¶
func (t *HuggingFaceTEIEmbeddings) Dimensions() int
Dimensions returns the dimension size of the embeddings.
func (*HuggingFaceTEIEmbeddings) EmbedBatch ¶
func (t *HuggingFaceTEIEmbeddings) EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)
EmbedBatch generates embeddings for multiple texts.
func (*HuggingFaceTEIEmbeddings) ModelName ¶
func (t *HuggingFaceTEIEmbeddings) ModelName() string
ModelName returns the name of the embedding model.
type OpenAIConfig ¶
type OpenAIConfig struct {
// APIKey for authentication
APIKey string `yaml:"api_key" json:"api_key"`
// Model specifies which OpenAI embedding model to use
// Options: "text-embedding-3-small" (1536 dims), "text-embedding-3-large" (3072 dims)
Model string `yaml:"model" json:"model"`
// BaseURL is the API endpoint (default: https://api.openai.com/v1)
BaseURL string `yaml:"base_url,omitempty" json:"base_url,omitempty"`
// Dimensions allows reducing embedding dimensions (only for text-embedding-3 models)
Dimensions int `yaml:"dimensions,omitempty" json:"dimensions,omitempty"`
}
OpenAIConfig contains OpenAI-specific embedding settings.
func (*OpenAIConfig) Validate ¶
func (oc *OpenAIConfig) Validate() error
Validate checks if OpenAI configuration is valid.
type OpenAIEmbeddings ¶
type OpenAIEmbeddings struct {
// contains filtered or unexported fields
}
OpenAIEmbeddings implements EmbeddingService using OpenAI's API.
func (*OpenAIEmbeddings) Close ¶
func (o *OpenAIEmbeddings) Close() error
Close closes any resources held by the service.
func (*OpenAIEmbeddings) Dimensions ¶
func (o *OpenAIEmbeddings) Dimensions() int
Dimensions returns the dimension size of the embeddings.
func (*OpenAIEmbeddings) EmbedBatch ¶
EmbedBatch generates embeddings for multiple texts.
func (*OpenAIEmbeddings) ModelName ¶
func (o *OpenAIEmbeddings) ModelName() string
ModelName returns the name of the embedding model.
type ProviderFactory ¶
type ProviderFactory func(config Config) (EmbeddingService, error)
ProviderFactory is a function that creates an EmbeddingService from a Config.