Skip to content

Batches.Get returns empty InlinedEmbedContentResponses for completed embedding batch jobs #712

@AaronReboot

Description

@AaronReboot

Bug Description

Batches.Get() returns an empty InlinedEmbedContentResponses slice for completed batch embedding jobs, even though the API successfully computed all embeddings.

Root Cause

The Gemini Developer API returns embedding results under output.inlinedResponses.inlinedResponses, but batchJobDestinationFromMldev in batches.go looks for them at output.inlinedEmbedContentResponses.inlinedResponses:

// batches.go – batchJobDestinationFromMldev

// Line 37-45: reads output.inlinedResponses.inlinedResponses
// and converts them through inlinedResponseFromMldev (generate content converter)
fromInlinedResponses := getValueByPath(fromObject, []string{"inlinedResponses", "inlinedResponses"})

// Line 47-50: reads output.inlinedEmbedContentResponses.inlinedResponses
// This path does NOT exist in the actual API response, so it's always nil
fromInlinedEmbedContentResponses := getValueByPath(fromObject, []string{"inlinedEmbedContentResponses", "inlinedResponses"})

The API does not use a separate inlinedEmbedContentResponses key — embedding batch results come back under the same inlinedResponses key as generate content results, just with embedding-specific inner structure. The SDK's path lookup for the embed field never matches, so BatchJobDestination.InlinedEmbedContentResponses is always nil.

Steps to Reproduce

ctx := context.Background()
client, _ := genai.NewClient(ctx, &genai.ClientConfig{
    Backend: genai.BackendGeminiAPI,
    APIKey:  "...",
})

model := "gemini-embedding-001"
job, _ := client.Batches.CreateEmbeddings(ctx, &model, &genai.EmbeddingsBatchJobSource{
    InlinedRequests: &genai.EmbedContentBatch{
        Contents: []*genai.Content{
            genai.NewContentFromText("hello world", ""),
            genai.NewContentFromText("test embedding", ""),
        },
    },
}, nil)

// Poll until SUCCEEDED...
for {
    job, _ = client.Batches.Get(ctx, job.Name, nil)
    if job.State == genai.JobStateSucceeded {
        break
    }
    time.Sleep(10 * time.Second)
}

// BUG: InlinedEmbedContentResponses is nil despite job succeeding
fmt.Println(len(job.Dest.InlinedEmbedContentResponses)) // prints 0

Expected Behavior

job.Dest.InlinedEmbedContentResponses should contain the embedding vectors after a successful batch embedding job.

Actual Behavior

job.Dest.InlinedEmbedContentResponses is nil/empty. The embeddings are in the raw API response under metadata.output.inlinedResponses.inlinedResponses but the SDK never reads them into the InlinedEmbedContentResponses field.

Workaround

Make a raw HTTP GET to https://generativelanguage.googleapis.com/v1beta/{job.Name} and parse the JSON manually to extract embeddings from metadata.output.inlinedResponses.inlinedResponses[].response.embedding.values.

Environment

  • SDK version: v1.49.0 (latest, also confirmed on main)
  • Go version: 1.24
  • Backend: BackendGeminiAPI (Gemini Developer API)

Metadata

Metadata

Labels

api:gemini-apiIssues related to Gemini APIpriority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions