microsoft / microsoft/semantic-kernel

Bug: VertexAIEmbeddingGenerator hardcodes :predict, unusable with gemini-embedding models that only serve :embedContent

Open
#14,265 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
28.6k
Forks
4.8k
Avg merge
14h 13m
Merged PRs (30d)
18

Description

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

  • Language: C#
  • Source: Microsoft.SemanticKernel.Connectors.Google@1.75.0-alpha
  • AI model: gemini-embedding-2
  • IDE: JetBrains Rider
  • OS: Windows

Additional context
:predict API is hardcoded here:
https://github.com/microsoft/semantic-kernel/blob/383d102346b7b29c929e0257ef672a48898b5f66/dotnet/src/Connectors/Connectors.Google/Core/VertexAI/VertexAIEmbeddingClient.cs#L57

Similar problems raised in other repos:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in dotnet/src/Connectors/Connectors.Google/Core/VertexAI/VertexAIEmbeddingClient.cs at the hardcoded :predict endpoint, then run the provided gemini-embedding-2 reproduction. Determine how the model should select :embedContent and verify that GenerateAsync succeeds with the requested dimensions instead of returning FAILED_PRECONDITION.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, google-cloud
Domain
ai, api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.