Add embedding dimension override support

This commit is contained in:
wizardchen
2026-06-15 19:16:31 +08:00
committed by lyingbug
parent 90f8e8b390
commit 53e0333a53
27 changed files with 476 additions and 189 deletions
+15 -11
View File
@@ -16,15 +16,16 @@ import (
// JinaEmbedder implements text vectorization functionality using Jina AI API
// Jina API is mostly OpenAI-compatible but does NOT support truncate_prompt_tokens
type JinaEmbedder struct {
apiKey string
baseURL string
modelName string
dimensions int
modelID string
httpClient *http.Client
timeout time.Duration
maxRetries int
customHeaders map[string]string
apiKey string
baseURL string
modelName string
dimensions int
modelID string
httpClient *http.Client
timeout time.Duration
maxRetries int
customHeaders map[string]string
supportsDimensionOverride bool
EmbedderPooler
}
@@ -33,6 +34,10 @@ func (e *JinaEmbedder) SetCustomHeaders(headers map[string]string) {
e.customHeaders = headers
}
func (e *JinaEmbedder) SetSupportsDimensionOverride(supported bool) {
e.supportsDimensionOverride = supported
}
// JinaEmbedRequest represents a Jina embedding request
// Note: Jina uses 'truncate' (boolean) instead of 'truncate_prompt_tokens' (integer)
type JinaEmbedRequest struct {
@@ -146,8 +151,7 @@ func (e *JinaEmbedder) BatchEmbed(ctx context.Context, texts []string) ([][]floa
Truncate: true, // Enable truncation for long texts
}
// Only include dimensions if specified and greater than 0
if e.dimensions > 0 {
if e.supportsDimensionOverride && e.dimensions > 0 {
reqBody.Dimensions = e.dimensions
}