Documentation
¶
Index ¶
- Variables
- type Config
- type Embedder
- type EmbedderPooler
- type EmbedderType
- type Image
- type ImageEmbedder
- type ImageLimits
- type OllamaEmbedRequest
- type OllamaEmbedResponse
- type OllamaEmbedder
- func (e *OllamaEmbedder) BatchEmbed(ctx context.Context, texts []string) ([][]float32, error)
- func (e *OllamaEmbedder) Embed(ctx context.Context, text string) ([]float32, error)
- func (e *OllamaEmbedder) GetDimensions() int
- func (e *OllamaEmbedder) GetModelID() string
- func (e *OllamaEmbedder) GetModelName() string
- func (e *OllamaEmbedder) SetSupportsDimensionOverride(supported bool)
Constants ¶
This section is empty.
Variables ¶
var ErrImagesUnsupported = errors.New("embedding model does not accept images")
ErrImagesUnsupported is returned when an embedder is asked for an image vector its model or endpoint cannot produce.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Source types.ModelSource `json:"source"`
BaseURL string `json:"base_url"`
ModelName string `json:"model_name"`
APIKey string `json:"api_key"`
TruncatePromptTokens int `json:"truncate_prompt_tokens"`
Dimensions int `json:"dimensions"`
SupportsDimensionOverride bool `json:"supports_dimension_override"`
ModelID string `json:"model_id"`
Provider string `json:"provider"`
// MaxConcurrency caps concurrent background calls to this model; 0 falls
// back to the process-wide default (see limiter.GateN).
MaxConcurrency int `json:"max_concurrency"`
Spec *types.ModelSpecOverride `json:"spec,omitempty"`
ExtraConfig map[string]string `json:"extra_config"`
// CustomHeaders 允许在调用远程 API 时附加自定义 HTTP 请求头(类似 OpenAI Python SDK 的 extra_headers)。
CustomHeaders map[string]string `json:"custom_headers"`
AppID string
AppSecret string // 加密值,工厂函数调用方传入,使用前已解密
}
Config represents the embedder configuration
type Embedder ¶
type Embedder interface {
// Embed converts text to vector
Embed(ctx context.Context, text string) ([]float32, error)
// BatchEmbed converts multiple texts to vectors in batch
BatchEmbed(ctx context.Context, texts []string) ([][]float32, error)
// GetModelName returns the model name
GetModelName() string
// GetDimensions returns the vector dimensions
GetDimensions() int
// GetModelID returns the model ID
GetModelID() string
EmbedderPooler
}
Embedder defines the interface for text vectorization
func NewEmbedder ¶
func NewEmbedder(config Config, pooler EmbedderPooler, ollamaService *ollama.OllamaService) (Embedder, error)
NewEmbedder creates an embedder based on the configuration
type EmbedderPooler ¶
type EmbedderPooler interface {
BatchEmbedWithPool(ctx context.Context, model Embedder, texts []string) ([][]float32, error)
}
func NewBatchEmbedder ¶
func NewBatchEmbedder(pool *ants.Pool) EmbedderPooler
type ImageEmbedder ¶
type ImageEmbedder interface {
// AcceptsImages reports whether both the model and its endpoint take
// images.
AcceptsImages() bool
// ImageLimits are the vendor's documented per-image limits. The caller
// shrinks or converts an image to fit; an image outside them is refused.
ImageLimits() ImageLimits
// BatchEmbedImages converts images to vectors comparable with Embed's.
BatchEmbedImages(ctx context.Context, images []Image) ([][]float32, error)
}
ImageEmbedder is the image side of an Embedder whose model maps images into the same space as its text vectors, so that a text query can find an image. It is a separate interface because most embedders have no image side; use AsImageEmbedder rather than a type assertion, since every decorator implements it whether or not the model underneath does.
func AsImageEmbedder ¶
func AsImageEmbedder(e Embedder) (ImageEmbedder, bool)
AsImageEmbedder returns e's image side when its model accepts images.
type ImageLimits ¶
ImageLimits describes what one image may be; see imageprep.Limits.
type OllamaEmbedRequest ¶
type OllamaEmbedRequest struct {
Model string `json:"model"`
Prompt string `json:"prompt"`
TruncatePromptTokens int `json:"truncate_prompt_tokens"`
}
OllamaEmbedRequest represents an Ollama embedding request
type OllamaEmbedResponse ¶
type OllamaEmbedResponse struct {
Embedding []float32 `json:"embedding"`
}
OllamaEmbedResponse represents an Ollama embedding response
type OllamaEmbedder ¶
type OllamaEmbedder struct {
EmbedderPooler
// contains filtered or unexported fields
}
OllamaEmbedder implements text vectorization functionality using Ollama
func NewOllamaEmbedder ¶
func NewOllamaEmbedder(baseURL, modelName string, truncatePromptTokens int, dimensions int, modelID string, pooler EmbedderPooler, ollamaService *ollama.OllamaService, ) (*OllamaEmbedder, error)
NewOllamaEmbedder creates a new Ollama embedder
func (*OllamaEmbedder) BatchEmbed ¶
BatchEmbed converts multiple texts to vectors in batch
func (*OllamaEmbedder) GetDimensions ¶
func (e *OllamaEmbedder) GetDimensions() int
GetDimensions returns the vector dimensions
func (*OllamaEmbedder) GetModelID ¶
func (e *OllamaEmbedder) GetModelID() string
GetModelID returns the model ID
func (*OllamaEmbedder) GetModelName ¶
func (e *OllamaEmbedder) GetModelName() string
GetModelName returns the model name
func (*OllamaEmbedder) SetSupportsDimensionOverride ¶
func (e *OllamaEmbedder) SetSupportsDimensionOverride(supported bool)