Documentation
¶
Index ¶
- func ChooseModel(reqModel, defaultModel, fallback string) string
- type BaseConfig
- type BaseProvider
- func (p *BaseProvider) Dimensions() int
- func (p *BaseProvider) DoRequest(ctx context.Context, method, endpoint string, body any, ...) ([]byte, error)
- func (p *BaseProvider) EmbedDocuments(ctx context.Context, documents []string, ...) ([][]float64, error)
- func (p *BaseProvider) EmbedQuery(ctx context.Context, query string, ...) ([]float64, error)
- func (p *BaseProvider) MaxBatchSize() int
- func (p *BaseProvider) Name() string
- type CohereConfig
- type CohereProvider
- type EmbeddingData
- type EmbeddingRequest
- type EmbeddingResponse
- type EmbeddingUsage
- type GeminiConfig
- type GeminiProvider
- func (p *GeminiProvider) Dimensions() int
- func (p *GeminiProvider) Embed(ctx context.Context, req *EmbeddingRequest) (*EmbeddingResponse, error)
- func (p *GeminiProvider) EmbedDocuments(ctx context.Context, documents []string) ([][]float64, error)
- func (p *GeminiProvider) EmbedQuery(ctx context.Context, query string) ([]float64, error)
- func (p *GeminiProvider) MaxBatchSize() int
- func (p *GeminiProvider) Name() string
- type HealthStatus
- type InputType
- type JinaConfig
- type JinaProvider
- type OpenAIConfig
- type OpenAIProvider
- type Provider
- type VoyageConfig
- type VoyageProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BaseConfig ¶
type BaseConfig struct {
Name string
BaseURL string
APIKey string
Model string
Dimensions int
MaxBatch int
Timeout time.Duration
}
BaseConfig持有基础提供者的共同配置.
type BaseProvider ¶
type BaseProvider struct {
// contains filtered or unexported fields
}
BaseProvider为嵌入提供者提供了共同的功能.
func NewBaseProvider ¶
func NewBaseProvider(cfg BaseConfig) *BaseProvider
NewBase Provider创建了一个新的基础提供者.
func (*BaseProvider) Dimensions ¶
func (p *BaseProvider) Dimensions() int
func (*BaseProvider) DoRequest ¶
func (p *BaseProvider) DoRequest(ctx context.Context, method, endpoint string, body any, headers map[string]string) ([]byte, error)
Dorequest 执行 HTTP 请求, 并进行常见错误处理 。
func (*BaseProvider) EmbedDocuments ¶
func (p *BaseProvider) EmbedDocuments(ctx context.Context, documents []string, embedFn func(context.Context, *EmbeddingRequest) (*EmbeddingResponse, error)) ([][]float64, error)
嵌入文件嵌入多个文档。
func (*BaseProvider) EmbedQuery ¶
func (p *BaseProvider) EmbedQuery(ctx context.Context, query string, embedFn func(context.Context, *EmbeddingRequest) (*EmbeddingResponse, error)) ([]float64, error)
嵌入查询嵌入单个查询字符串.
func (*BaseProvider) MaxBatchSize ¶
func (p *BaseProvider) MaxBatchSize() int
func (*BaseProvider) Name ¶
func (p *BaseProvider) Name() string
type CohereConfig ¶
type CohereConfig struct {
providers.BaseProviderConfig `yaml:",inline"`
}
CohereConfig 配置 Cohere 嵌入提供者.
type CohereProvider ¶
type CohereProvider struct {
*BaseProvider
// contains filtered or unexported fields
}
Cohere Provider 执行使用 Cohere API的嵌入.
func NewCohereProvider ¶
func NewCohereProvider(cfg CohereConfig) *CohereProvider
NewCohere Provider创建了一个新的Cohere嵌入提供商.
func (*CohereProvider) Embed ¶
func (p *CohereProvider) Embed(ctx context.Context, req *EmbeddingRequest) (*EmbeddingResponse, error)
嵌入会使用Cohere生成嵌入.
func (*CohereProvider) EmbedDocuments ¶
func (p *CohereProvider) EmbedDocuments(ctx context.Context, documents []string) ([][]float64, error)
嵌入文件嵌入多个文档。
func (*CohereProvider) EmbedQuery ¶
嵌入查询嵌入了单个查询.
type EmbeddingData ¶
type EmbeddingData struct {
Index int `json:"index"`
Embedding []float64 `json:"embedding"`
Object string `json:"object,omitempty"` // "embedding"
}
EmbeddingData 表示单个嵌入结果.
type EmbeddingRequest ¶
type EmbeddingRequest struct {
Input []string `json:"input"` // Text inputs to embed
Model string `json:"model,omitempty"` // Model to use
Dimensions int `json:"dimensions,omitempty"` // Output dimensions (for models that support it)
EncodingFormat string `json:"encoding_format,omitempty"` // float or base64
InputType InputType `json:"input_type,omitempty"` // query, document, etc.
Truncate bool `json:"truncate,omitempty"` // Auto-truncate long inputs
Metadata map[string]string `json:"metadata,omitempty"`
}
EmbeddingRequest 表示生成嵌入的请求.
type EmbeddingResponse ¶
type EmbeddingResponse struct {
ID string `json:"id,omitempty"`
Provider string `json:"provider"`
Model string `json:"model"`
Embeddings []EmbeddingData `json:"embeddings"`
Usage EmbeddingUsage `json:"usage"`
CreatedAt time.Time `json:"created_at,omitempty"`
}
EmbeddingResponse 表示嵌入请求的响应.
type EmbeddingUsage ¶
type EmbeddingUsage struct {
PromptTokens int `json:"prompt_tokens"`
TotalTokens int `json:"total_tokens"`
Cost float64 `json:"cost,omitempty"` // USD
}
EmbeddingUsage 表示嵌入请求的 Token 用量.
type GeminiConfig ¶
type GeminiConfig struct {
providers.BaseProviderConfig `yaml:",inline"`
}
GeminiConfig 配置 Gemini 嵌入提供者. 嵌入 providers.BaseProviderConfig 以复用 APIKey、BaseURL、Model、Timeout 字段。
func DefaultGeminiConfig ¶
func DefaultGeminiConfig() GeminiConfig
DefaultGeminiConfig 返回默认 Gemini 嵌入配置.
type GeminiProvider ¶
type GeminiProvider struct {
// contains filtered or unexported fields
}
GeminiProvider 使用 Google Gemini API 执行嵌入. 注: Gemini 使用不同的端点格式: /models/{model}:embedContent
func NewGeminiProvider ¶
func NewGeminiProvider(cfg GeminiConfig) *GeminiProvider
NewGeminiProvider 创建新的 Gemini 嵌入提供者.
func (*GeminiProvider) Dimensions ¶
func (p *GeminiProvider) Dimensions() int
func (*GeminiProvider) Embed ¶
func (p *GeminiProvider) Embed(ctx context.Context, req *EmbeddingRequest) (*EmbeddingResponse, error)
Embed 使用 Gemini API 生成嵌入.
func (*GeminiProvider) EmbedDocuments ¶
func (p *GeminiProvider) EmbedDocuments(ctx context.Context, documents []string) ([][]float64, error)
EmbedDocuments 嵌入多个文档.
func (*GeminiProvider) EmbedQuery ¶
EmbedQuery 嵌入单个查询.
func (*GeminiProvider) MaxBatchSize ¶
func (p *GeminiProvider) MaxBatchSize() int
func (*GeminiProvider) Name ¶
func (p *GeminiProvider) Name() string
type HealthStatus ¶
type HealthStatus = llm.HealthStatus
HealthStatus 表示提供者的健康检查结果. 这是 llm.HealthStatus 的类型别名,统一 Provider 级别的健康状态定义。
type InputType ¶
type InputType string
InputType 指定嵌入优化的输入类型.
const ( InputTypeQuery InputType = "query" // For search queries InputTypeDocument InputType = "document" // For documents to be indexed InputTypeClassify InputType = "classification" InputTypeClustering InputType = "clustering" InputTypeCodeQuery InputType = "code_query" // Voyage code-specific InputTypeCodeDoc InputType = "code_document" )
type JinaConfig ¶
type JinaConfig struct {
providers.BaseProviderConfig `yaml:",inline"`
}
JinaConfig 配置 Jina AI 嵌入提供者.
type JinaProvider ¶
type JinaProvider struct {
*BaseProvider
// contains filtered or unexported fields
}
Jina Provider 执行使用 Jina AI 的 API 嵌入.
func NewJinaProvider ¶
func NewJinaProvider(cfg JinaConfig) *JinaProvider
新JinaProvider创建了新的Jina AI嵌入服务商.
func (*JinaProvider) Embed ¶
func (p *JinaProvider) Embed(ctx context.Context, req *EmbeddingRequest) (*EmbeddingResponse, error)
嵌入会使用Jina AI生成嵌入.
func (*JinaProvider) EmbedDocuments ¶
嵌入文件嵌入多个文档。
func (*JinaProvider) EmbedQuery ¶
嵌入查询嵌入了单个查询.
type OpenAIConfig ¶
type OpenAIConfig struct {
providers.BaseProviderConfig `yaml:",inline"`
Dimensions int `json:"dimensions,omitempty" yaml:"dimensions,omitempty"` // 256, 1024, 3072
}
OpenAIConfig 配置 OpenAI 嵌入提供者. 嵌入 providers.BaseProviderConfig 以复用 APIKey、BaseURL、Model、Timeout 字段。
func DefaultOpenAIConfig ¶
func DefaultOpenAIConfig() OpenAIConfig
默认 OpenAIConfig 返回默认 OpenAI 嵌入配置.
type OpenAIProvider ¶
type OpenAIProvider struct {
*BaseProvider
// contains filtered or unexported fields
}
OpenAIProvider 执行使用 OpenAI 的 API 嵌入.
func NewOpenAIProvider ¶
func NewOpenAIProvider(cfg OpenAIConfig) *OpenAIProvider
NewOpenAIProvider创建了新的OpenAI嵌入提供商.
func (*OpenAIProvider) Embed ¶
func (p *OpenAIProvider) Embed(ctx context.Context, req *EmbeddingRequest) (*EmbeddingResponse, error)
嵌入为给定输入生成嵌入.
func (*OpenAIProvider) EmbedDocuments ¶
func (p *OpenAIProvider) EmbedDocuments(ctx context.Context, documents []string) ([][]float64, error)
嵌入文件嵌入多个文档。
func (*OpenAIProvider) EmbedQuery ¶
嵌入查询嵌入了单个查询.
type Provider ¶
type Provider interface {
// Embed 为给定输入生成嵌入.
Embed(ctx context.Context, req *EmbeddingRequest) (*EmbeddingResponse, error)
// EmbedQuery 是嵌入单个查询的便捷方法.
EmbedQuery(ctx context.Context, query string) ([]float64, error)
// EmbedDocuments 是嵌入多个文档的便捷方法.
EmbedDocuments(ctx context.Context, documents []string) ([][]float64, error)
// Name 返回提供者名称.
Name() string
// Dimensions 返回默认嵌入维度.
Dimensions() int
// MaxBatchSize 返回支持的最大批量大小.
MaxBatchSize() int
}
Provider 定义统一的嵌入提供者接口.
type VoyageConfig ¶
type VoyageConfig struct {
providers.BaseProviderConfig `yaml:",inline"`
}
VoyageConfig 配置 Voyage AI 嵌入提供者.
func DefaultVoyageConfig ¶
func DefaultVoyageConfig() VoyageConfig
默认 VoyageConfig 返回默认 Voyage AI 配置.
type VoyageProvider ¶
type VoyageProvider struct {
*BaseProvider
// contains filtered or unexported fields
}
Voyage Provider 执行使用 Voyage AI 的 API 嵌入.
func NewVoyageProvider ¶
func NewVoyageProvider(cfg VoyageConfig) *VoyageProvider
NewVoyage Provider创建了一个新的Voyage AI嵌入提供商.
func (*VoyageProvider) Embed ¶
func (p *VoyageProvider) Embed(ctx context.Context, req *EmbeddingRequest) (*EmbeddingResponse, error)
Embed使用Voyage AI生成嵌入.
func (*VoyageProvider) EmbedDocuments ¶
func (p *VoyageProvider) EmbedDocuments(ctx context.Context, documents []string) ([][]float64, error)
嵌入文件嵌入多个文档。
func (*VoyageProvider) EmbedQuery ¶
嵌入查询嵌入了单个查询.