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