fix:dimensions not sent in embedding API requests (#1654)
fix:dimensions not sent in embedding API requests
This commit is contained in:
@@ -39,10 +39,16 @@ func (e *AliyunEmbedder) SetCustomHeaders(headers map[string]string) {
|
||||
e.customHeaders = headers
|
||||
}
|
||||
|
||||
// AliyunEmbedParameters represents the parameters for Aliyun DashScope multimodal embedding
|
||||
type AliyunEmbedParameters struct {
|
||||
Dimension int `json:"dimension,omitempty"`
|
||||
}
|
||||
|
||||
// AliyunEmbedRequest represents an Aliyun DashScope multimodal embedding request
|
||||
type AliyunEmbedRequest struct {
|
||||
Model string `json:"model"`
|
||||
Input AliyunEmbedInput `json:"input"`
|
||||
Model string `json:"model"`
|
||||
Input AliyunEmbedInput `json:"input"`
|
||||
Parameters *AliyunEmbedParameters `json:"parameters,omitempty"`
|
||||
}
|
||||
|
||||
// AliyunEmbedInput represents the input structure for Aliyun embedding
|
||||
@@ -188,6 +194,9 @@ func (e *AliyunEmbedder) BatchEmbed(ctx context.Context, texts []string) ([][]fl
|
||||
Contents: contents,
|
||||
},
|
||||
}
|
||||
if e.dimensions > 0 {
|
||||
reqBody.Parameters = &AliyunEmbedParameters{Dimension: e.dimensions}
|
||||
}
|
||||
|
||||
jsonData, err := json.Marshal(reqBody)
|
||||
if err != nil {
|
||||
|
||||
@@ -38,6 +38,7 @@ type NvidiaEmbedRequest struct {
|
||||
Model string `json:"model"`
|
||||
Input []string `json:"input"`
|
||||
EncodingFormat string `json:"encoding_format,omitempty"`
|
||||
Dimensions int `json:"dimensions,omitempty"`
|
||||
TruncatePromptTokens int `json:"truncate_prompt_tokens,omitempty"`
|
||||
InputType string `json:"input_type,omitempty"`
|
||||
}
|
||||
@@ -144,6 +145,7 @@ func (e *NvidiaEmbedder) BatchEmbed(ctx context.Context, texts []string) ([][]fl
|
||||
Model: e.modelName,
|
||||
Input: texts,
|
||||
EncodingFormat: "float",
|
||||
Dimensions: e.dimensions,
|
||||
InputType: "passage",
|
||||
}
|
||||
isQuery, _ := ctx.Value(types.EmbedQueryContextKey).(bool)
|
||||
|
||||
@@ -88,9 +88,10 @@ func (e *OllamaEmbedder) BatchEmbed(ctx context.Context, texts []string) ([][]fl
|
||||
|
||||
// Create request
|
||||
req := &ollamaapi.EmbedRequest{
|
||||
Model: e.modelName,
|
||||
Input: texts,
|
||||
Options: make(map[string]interface{}),
|
||||
Model: e.modelName,
|
||||
Input: texts,
|
||||
Dimensions: e.dimensions,
|
||||
Options: make(map[string]interface{}),
|
||||
}
|
||||
|
||||
// Set truncation parameters
|
||||
|
||||
@@ -33,6 +33,7 @@ type OpenAIEmbedRequest struct {
|
||||
Model string `json:"model"`
|
||||
Input []string `json:"input"`
|
||||
EncodingFormat string `json:"encoding_format,omitempty"`
|
||||
Dimensions int `json:"dimensions,omitempty"`
|
||||
TruncatePromptTokens int `json:"truncate_prompt_tokens,omitempty"`
|
||||
}
|
||||
|
||||
@@ -161,6 +162,7 @@ func (e *OpenAIEmbedder) BatchEmbed(ctx context.Context, texts []string) ([][]fl
|
||||
Model: e.modelName,
|
||||
Input: texts,
|
||||
EncodingFormat: "float",
|
||||
Dimensions: e.dimensions,
|
||||
TruncatePromptTokens: e.truncatePromptTokens,
|
||||
}
|
||||
|
||||
|
||||
@@ -41,8 +41,9 @@ func (e *VolcengineEmbedder) SetCustomHeaders(headers map[string]string) {
|
||||
|
||||
// VolcengineEmbedRequest represents a Volcengine Ark multimodal embedding request
|
||||
type VolcengineEmbedRequest struct {
|
||||
Model string `json:"model"`
|
||||
Input []VolcengineInputContent `json:"input"`
|
||||
Model string `json:"model"`
|
||||
Input []VolcengineInputContent `json:"input"`
|
||||
Dimensions int `json:"dimensions,omitempty"`
|
||||
}
|
||||
|
||||
// VolcengineInputContent represents a single input item for Volcengine
|
||||
@@ -199,8 +200,9 @@ func (e *VolcengineEmbedder) BatchEmbed(ctx context.Context, texts []string) ([]
|
||||
}
|
||||
|
||||
reqBody := VolcengineEmbedRequest{
|
||||
Model: e.modelName,
|
||||
Input: input,
|
||||
Model: e.modelName,
|
||||
Input: input,
|
||||
Dimensions: e.dimensions,
|
||||
}
|
||||
|
||||
jsonData, err := json.Marshal(reqBody)
|
||||
|
||||
@@ -56,6 +56,7 @@ func NewWeKnoraCloudEmbedder(config Config) (*WeKnoraCloudEmbedder, error) {
|
||||
type weKnoraCloudEmbedRequest struct {
|
||||
Model string `json:"model"`
|
||||
Input []string `json:"input"`
|
||||
Dimensions int `json:"dimensions,omitempty"`
|
||||
TruncatePromptTokens int `json:"truncate_prompt_tokens,omitempty"`
|
||||
}
|
||||
|
||||
@@ -78,7 +79,7 @@ func (e *WeKnoraCloudEmbedder) Embed(ctx context.Context, text string) ([]float3
|
||||
}
|
||||
|
||||
func (e *WeKnoraCloudEmbedder) BatchEmbed(ctx context.Context, texts []string) ([][]float32, error) {
|
||||
reqBody := weKnoraCloudEmbedRequest{Model: e.effectiveModelName(), Input: texts}
|
||||
reqBody := weKnoraCloudEmbedRequest{Model: e.effectiveModelName(), Input: texts, Dimensions: e.dimensions}
|
||||
bodyBytes, err := json.Marshal(reqBody)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("weknoracloud embedder: marshal: %w", err)
|
||||
|
||||
@@ -33,6 +33,7 @@ type ZhipuEmbedder struct {
|
||||
type ZhipuEmbedRequest struct {
|
||||
Model string `json:"model"`
|
||||
Input []string `json:"input"`
|
||||
Dimensions int `json:"dimensions,omitempty"`
|
||||
TruncatePromptTokens int `json:"truncate_prompt_tokens,omitempty"`
|
||||
}
|
||||
|
||||
@@ -148,6 +149,7 @@ func (e *ZhipuEmbedder) BatchEmbed(ctx context.Context, texts []string) ([][]flo
|
||||
reqBody := ZhipuEmbedRequest{
|
||||
Model: e.modelName,
|
||||
Input: texts,
|
||||
Dimensions: e.dimensions,
|
||||
TruncatePromptTokens: e.truncatePromptTokens,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user