Describe the bug
Using VertexAIEmbeddingGenerator with model "gemini-embedding-2" will result in 400 FAILED_PRECONDITION
To Reproduce
Run the VertexAIEmbeddingGenerator generation with the gemini-embedding-2 model:
#:package Microsoft.SemanticKernel.Connectors.Google@1.75.0-alpha
#:property NoWarn=SKEXP0001;SKEXP0070
using System.Net.Http.Json;
using System.Text.Json;
using Microsoft.Extensions.AI;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.Google;
const string ModelId = "gemini-embedding-2";
const int Dimensions = 768;
var token = Require("GOOGLE_ACCESS_TOKEN");
var projectId = Require("GOOGLE_PROJECT_ID");
var location = Environment.GetEnvironmentVariable("GOOGLE_LOCATION") is { Length: > 0 } l ? l : "us-central1";
Console.WriteLine($"model={ModelId} project={projectId} location={location} dimensions={Dimensions}");
Console.WriteLine($"SK Connectors.Google = {typeof(VertexAIEmbeddingGenerator).Assembly.GetName().Version}");
Console.WriteLine();
try
{
IEmbeddingGenerator<string, Embedding<float>> generator = new VertexAIEmbeddingGenerator(
modelId: ModelId,
bearerKey: token,
location: location,
projectId: projectId,
dimensions: Dimensions);
var embeddings = await generator.GenerateAsync(["test"]);
Console.WriteLine($" UNEXPECTED SUCCESS: {embeddings[0].Vector.Length} floats");
}
catch (HttpOperationException ex)
{
Console.WriteLine($" FAILED status={ex.StatusCode}");
Console.WriteLine($" message={ex.Message}");
Console.WriteLine($" body={Trim(ex.ResponseContent)}");
}
catch (Exception ex)
{
Console.WriteLine($" FAILED {ex.GetType().Name}: {ex.Message}");
}
Expected behavior
VertexAIEmbeddingGenerator should correctly resolve to use the :embedContent endpoint in this case, as the :predict endpoint is no longer supported for gemini-embedding-2
Platform
Additional context
:predict API is hardcoded here:
|
this._embeddingEndpoint = new Uri($"{baseUri}/{versionSubLink}/projects/{projectId}/locations/{location}/publishers/google/models/{this._embeddingModelId}:predict"); |
Similar problems raised in other repos:
Describe the bug
Using VertexAIEmbeddingGenerator with model "gemini-embedding-2" will result in 400 FAILED_PRECONDITION
To Reproduce
Run the VertexAIEmbeddingGenerator generation with the gemini-embedding-2 model:
Expected behavior
VertexAIEmbeddingGenerator should correctly resolve to use the :embedContent endpoint in this case, as the :predict endpoint is no longer supported for gemini-embedding-2
Platform
Additional context
:predict API is hardcoded here:
semantic-kernel/dotnet/src/Connectors/Connectors.Google/Core/VertexAI/VertexAIEmbeddingClient.cs
Line 57 in 383d102
Similar problems raised in other repos:
gemini-embedding-2fails with 400 FAILED_PRECONDITION (embedding model only calls:predict, not:embedContent) vercel/ai#15853vertex_ai/gemini-embedding-2-previewroutes to:predictendpoint, returnsFAILED_PRECONDITIONBerriAI/litellm#23508