Skip to content

Commit ac870e7

Browse files
committed
fix: align embedding generator with embed config changes
1 parent 856304c commit ac870e7

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

src/libs/Google.Gemini/Extensions/GeminiClient.EmbeddingGenerator.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,18 @@ public partial class GeminiClient : Meai.IEmbeddingGenerator<string, Meai.Embedd
2626

2727
var modelId = options?.ModelId ?? "gemini-embedding-001";
2828

29-
EmbedContentRequestTaskType? taskType = null;
29+
EmbedContentConfigTaskType? taskType = null;
3030
string? title = null;
3131
if (options?.AdditionalProperties is { Count: > 0 } additionalProps)
3232
{
3333
if (additionalProps.TryGetValue("TaskType", out var taskTypeVal))
3434
{
3535
taskType = taskTypeVal switch
3636
{
37-
EmbedContentRequestTaskType enumVal => enumVal,
38-
string str => EmbedContentRequestTaskTypeExtensions.ToEnum(str),
37+
EmbedContentConfigTaskType enumVal => enumVal,
38+
EmbedContentRequestTaskType requestEnumVal => EmbedContentConfigTaskTypeExtensions.ToEnum(
39+
requestEnumVal.ToValueString()),
40+
string str => EmbedContentConfigTaskTypeExtensions.ToEnum(str),
3941
_ => null,
4042
};
4143
}
@@ -46,17 +48,25 @@ public partial class GeminiClient : Meai.IEmbeddingGenerator<string, Meai.Embedd
4648
}
4749
}
4850

51+
var embedContentConfig =
52+
options?.Dimensions is not null || taskType is not null || title is not null
53+
? new EmbedContentConfig
54+
{
55+
OutputDimensionality = options?.Dimensions,
56+
TaskType = taskType,
57+
Title = title,
58+
}
59+
: null;
60+
4961
var requests = values
5062
.Select(text => new EmbedContentRequest
5163
{
64+
EmbedContentConfig = embedContentConfig,
5265
Model = $"models/{modelId}",
5366
Content = new Content
5467
{
5568
Parts = [new Part { Text = text }],
5669
},
57-
OutputDimensionality = options?.Dimensions,
58-
TaskType = taskType,
59-
Title = title,
6070
})
6171
.ToList();
6272

0 commit comments

Comments
 (0)