Skip to content

fix(openai-adapters): read Gemini embeddings from correct response field - #12517

Open
Pluviobyte wants to merge 1 commit into
continuedev:mainfrom
Pluviobyte:fix/gemini-embeddings-response-field
Open

fix(openai-adapters): read Gemini embeddings from correct response field#12517
Pluviobyte wants to merge 1 commit into
continuedev:mainfrom
Pluviobyte:fix/gemini-embeddings-response-field

Conversation

@Pluviobyte

@Pluviobyte Pluviobyte commented May 29, 2026

Copy link
Copy Markdown

Description

The Gemini embeddings adapter reads the wrong field from the :batchEmbedContents response. In packages/openai-adapters/src/apis/Gemini.ts, embed() did:

data: data.batchEmbedContents.map((embedding: any) => embedding.values),

but the Gemini API returns the vectors under embeddings, not batchEmbedContents. That field is always undefined, so every embeddings request through the Gemini adapter throws:

TypeError: Cannot read properties of undefined (reading 'map')

This breaks embeddings (e.g. @codebase / @docs indexing) for anyone configuring Gemini as their embed model. The path is reachable: core/llm/llms/Gemini.ts sets useOpenAIAdapterFor = ["chat", "embed", ...], so embeddings go through GeminiApi.embed().

The fix mirrors the core implementation, which already reads the correct field:

// core/llm/llms/Gemini.ts
return data.embeddings.map((embedding: any) => embedding.values);

I also removed the usage block, which read two more non-existent fields (data.total_tokens / data.prompt_tokens). The batchEmbedContents response carries no token usage, and embedding() already defaults usage to zeros — matching core, which sets no usage.

Checklist

  • I've read the contributing guide
  • The relevant docs, if any, have been updated or created
  • The relevant tests, if any, have been updated or created

Screen recording or screenshot

N/A — backend crash fix; covered by the regression test below.

Tests

Added an embed test in packages/openai-adapters/src/apis/Gemini.test.ts that mocks the real :batchEmbedContents response shape ({ embeddings: [{ values }] }) and asserts the parsed vectors. Verified it fails on the old code with Cannot read properties of undefined (reading 'map') and passes with the fix. npx tsc --noEmit and prettier --check both pass locally.

Made with Cursor


Summary by cubic

Fixes a crash in the Gemini embeddings adapter by reading vectors from the correct response field. Restores embeddings for Gemini embed models and aligns adapter behavior with core.

  • Bug Fixes

    • packages/openai-adapters/src/apis/Gemini.ts: embed() now reads data.embeddings instead of data.batchEmbedContents.
    • Removed the invalid usage block (nonexistent token fields).
  • Tests

    • Added a regression test in packages/openai-adapters/src/apis/Gemini.test.ts that mocks the :batchEmbedContents response and asserts parsed vectors.

Written for commit e5f1548. Summary will update on new commits.

Review in cubic

The Gemini adapter's embed() reads `data.batchEmbedContents` from the
`:batchEmbedContents` response, but that field does not exist — the Gemini
API returns the vectors under `embeddings`. Every embeddings request
through the Gemini adapter therefore throws "Cannot read properties of
undefined (reading 'map')", breaking @codebase / docs indexing for anyone
using Gemini as their embeddings provider.

The core Gemini implementation (core/llm/llms/Gemini.ts) already reads
`data.embeddings`; this aligns the adapter with it and drops the usage
block that read two more non-existent fields. Adds a regression test that
feeds the real response shape and asserts the parsed vectors.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Pluviobyte
Pluviobyte requested a review from a team as a code owner May 29, 2026 06:07
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label May 29, 2026
@Pluviobyte

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@github-actions

github-actions Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

@Pluviobyte

Copy link
Copy Markdown
Author

I checked the remaining failing statuses. The GitHub Actions checks are green except the old macOS VSIX job showing cancelled, and the Continuous AI failure target I opened returns Cannot GET /api/agent-check-summary/..., so there is no actionable failure detail exposed from the external check.

Could a maintainer rerun/waive the Continuous AI statuses or share the specific task output? I can address any concrete finding once the external check exposes it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant