Skip to content

fix(gemini): assign correct indices in batch embedding response - #25656

Merged
krrish-berri-2 merged 1 commit into
BerriAI:litellm_oss_staging_04_13_2026_p1from
lucassz:fix/gemini-batch-embedding-indices
Apr 14, 2026
Merged

fix(gemini): assign correct indices in batch embedding response#25656
krrish-berri-2 merged 1 commit into
BerriAI:litellm_oss_staging_04_13_2026_p1from
lucassz:fix/gemini-batch-embedding-indices

Conversation

@lucassz

@lucassz lucassz commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

Relevant issues

The Gemini batchEmbedContents response handler hardcoded index=0 for every embedding in the response. Any consumer relying on the OpenAI-format index field to match embeddings back to inputs would silently get wrong associations.

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/test_litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

CI (LiteLLM team)

CI status guideline:

  • 50-55 passing tests: main is stable with minor issues.
  • 45-49 passing tests: acceptable but needs attention
  • <= 40 passing tests: unstable; be careful with your merges and assess the risk.
  • Branch creation CI run
    Link:

  • CI run for the last commit
    Link:

  • Merge / cherry-pick CI run
    Links:

Screenshots / Proof of Fix

Added unit test asserting sequential indices and correct vector ordering for a batch response.

Type

🐛 Bug Fix

Changes

Use enumerate in process_response so each embedding gets its positional index instead of 0.

@vercel

vercel Bot commented Apr 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Apr 13, 2026 11:05pm

Request Review

@CLAassistant

CLAassistant commented Apr 13, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@lucassz

lucassz commented Apr 13, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai

@lucassz
lucassz force-pushed the fix/gemini-batch-embedding-indices branch from 1bd8316 to 2c1a868 Compare April 13, 2026 23:00
@greptile-apps

greptile-apps Bot commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a bug in process_response within the Gemini batch embeddings transformation where every embedding in a batch response was assigned index=0 instead of its correct positional index. The one-line fix replaces the bare for embedding in loop with enumerate, and a new unit test verifies sequential indices and value ordering without making real network calls.

Confidence Score: 5/5

This PR is safe to merge — it's a minimal, well-tested bug fix with no side effects.

Single-line correctness fix with a targeted unit test that makes no real network calls. No backwards-incompatible changes, no security implications, and all custom rules are satisfied.

No files require special attention.

Important Files Changed

Filename Overview
litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_transformation.py Correct one-line fix: enumerate replaces hardcoded index=0, assigning proper sequential indices to batch embeddings.
tests/litellm/llms/vertex_ai/test_gemini_batch_embeddings.py New unit test directly calls process_response with mock data, asserting correct sequential indices and value ordering; no real network calls.

Reviews (2): Last reviewed commit: "fix(gemini): assign correct indices in b..." | Re-trigger Greptile

@codspeed-hq

codspeed-hq Bot commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 16 untouched benchmarks


Comparing lucassz:fix/gemini-batch-embedding-indices (fbcf870) with main (548225e)

Open in CodSpeed

### Background

The Gemini batchEmbedContents response handler hardcoded `index=0` for
every embedding in the response. Any consumer relying on the OpenAI-format
`index` field to match embeddings back to inputs would silently get wrong
associations.

### Changes

Use `enumerate` in `process_response` so each embedding gets its
positional index instead of 0.

### Test Plan

Added unit test asserting sequential indices and correct vector ordering
for a 3-element batch response.
@codecov

codecov Bot commented Apr 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...i_embeddings/batch_embed_content_transformation.py 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@krrish-berri-2
krrish-berri-2 changed the base branch from main to litellm_oss_staging_04_13_2026_p1 April 14, 2026 01:28
@krrish-berri-2
krrish-berri-2 merged commit 1186544 into BerriAI:litellm_oss_staging_04_13_2026_p1 Apr 14, 2026
49 of 51 checks passed
@lucassz
lucassz deleted the fix/gemini-batch-embedding-indices branch April 14, 2026 17:46
Sameerlite pushed a commit that referenced this pull request Apr 14, 2026
### Background

The Gemini batchEmbedContents response handler hardcoded `index=0` for
every embedding in the response. Any consumer relying on the OpenAI-format
`index` field to match embeddings back to inputs would silently get wrong
associations.

### Changes

Use `enumerate` in `process_response` so each embedding gets its
positional index instead of 0.

### Test Plan

Added unit test asserting sequential indices and correct vector ordering
for a 3-element batch response.
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…iAI#25656)

### Background

The Gemini batchEmbedContents response handler hardcoded `index=0` for
every embedding in the response. Any consumer relying on the OpenAI-format
`index` field to match embeddings back to inputs would silently get wrong
associations.

### Changes

Use `enumerate` in `process_response` so each embedding gets its
positional index instead of 0.

### Test Plan

Added unit test asserting sequential indices and correct vector ordering
for a 3-element batch response.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants