Add embedding dimension override support
This commit is contained in:
@@ -16,15 +16,16 @@ import (
|
||||
|
||||
// NvidiaEmbedder implements text vectorization functionality using NVIDIA API
|
||||
type NvidiaEmbedder 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 *NvidiaEmbedder) SetCustomHeaders(headers map[string]string) {
|
||||
e.customHeaders = headers
|
||||
}
|
||||
|
||||
func (e *NvidiaEmbedder) SetSupportsDimensionOverride(supported bool) {
|
||||
e.supportsDimensionOverride = supported
|
||||
}
|
||||
|
||||
// NvidiaEmbedRequest represents an NVIDIA embedding request
|
||||
type NvidiaEmbedRequest struct {
|
||||
Model string `json:"model"`
|
||||
@@ -145,9 +150,11 @@ func (e *NvidiaEmbedder) BatchEmbed(ctx context.Context, texts []string) ([][]fl
|
||||
Model: e.modelName,
|
||||
Input: texts,
|
||||
EncodingFormat: "float",
|
||||
Dimensions: e.dimensions,
|
||||
InputType: "passage",
|
||||
}
|
||||
if e.supportsDimensionsParam() {
|
||||
reqBody.Dimensions = e.dimensions
|
||||
}
|
||||
isQuery, _ := ctx.Value(types.EmbedQueryContextKey).(bool)
|
||||
if isQuery {
|
||||
reqBody.InputType = "query"
|
||||
@@ -202,6 +209,10 @@ func (e *NvidiaEmbedder) GetModelName() string {
|
||||
return e.modelName
|
||||
}
|
||||
|
||||
func (e *NvidiaEmbedder) supportsDimensionsParam() bool {
|
||||
return e.supportsDimensionOverride && e.dimensions > 0
|
||||
}
|
||||
|
||||
// GetDimensions returns the vector dimensions
|
||||
func (e *NvidiaEmbedder) GetDimensions() int {
|
||||
return e.dimensions
|
||||
|
||||
Reference in New Issue
Block a user