Skip to content

fix(embeddings): forward output dimensions to Gemini for consistent embedding dims - #4449

Merged
diegosouzapw merged 1 commit into
release/v3.8.32from
feat/port-pr-1366-gemini-embedding-dimensions
Jun 20, 2026
Merged

diegosouzapw merged 1 commit into
release/v3.8.32from
feat/port-pr-1366-gemini-embedding-dimensions

Conversation

@diegosouzapw

Copy link
Copy Markdown
Owner

Summary

Forward the OpenAI-style dimensions request field to the Gemini-native
outputDimensionality field so clients can reliably get the embedding
vector size they ask for.

Ported from upstream PR decolua/9router#1366 (author @nguyenha935).

Why

Gemini embedding models (text-embedding-004, gemini-embedding-001,
gemini-embedding-2-preview) default to 3072-dim vectors. OpenAI-compatible
clients typically request a smaller size (e.g. 1536 for pgvector schemas)
via the OpenAI dimensions field. OmniRoute already forwarded dimensions to
Gemini's OpenAI-compatibility endpoint (/v1beta/openai/embeddings), but
Google's compatibility shim does not document the dimensions →
outputDimensionality translation — so callers still received full-size
vectors back. The upstream PR fixes the same gap on the native :embedContent
/ :batchEmbedContents path; this port applies the equivalent fix to
OmniRoute's OpenAI-compat embeddings handler.

What changed

  • open-sse/handlers/embeddings.ts — when provider === "gemini" and the
    client sent a positive finite dimensions, mirror it into the
    outputDimensionality field of the upstream body (alongside the existing
    dimensions forwarding). 0, NaN, negative values are ignored. Other
    providers are unchanged.
  • tests/unit/embeddings-gemini-dimensions.test.ts — 5 new tests covering:
    Gemini single input, Gemini batch input, omitted dimensions (no injection),
    non-Gemini providers (no leak), invalid dimensions (0 rejected).

Test plan

  • node --import tsx/esm --test tests/unit/embeddings-gemini-dimensions.test.ts → 5/5 pass (RED→GREEN confirmed)
  • node --import tsx/esm --test tests/unit/embeddings-nvidia-input-type.test.ts tests/unit/embeddings-handler.test.ts tests/unit/embeddings-auth.test.ts → 24/24 pass (no regression)
  • npx eslint open-sse/handlers/embeddings.ts tests/unit/embeddings-gemini-dimensions.test.ts → clean
  • Husky pre-commit + pre-push hooks → pass

Attribution

Original author: @nguyenha935 (upstream decolua/9router#1366).

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Gemini embedding models (text-embedding-004, gemini-embedding-001 /
-2-preview) default to 3072-dim vectors. OpenAI-compatible clients
request a specific size (e.g. 1536 for pgvector schemas) via the
`dimensions` field, but Google's OpenAI-compatibility shim at
/v1beta/openai/embeddings does not document the `dimensions` →
`outputDimensionality` translation. OmniRoute now mirrors the
request value into the Gemini-native `outputDimensionality` field
alongside the OpenAI-style `dimensions`, so the upstream returns
the requested vector size regardless of the shim behavior. Other
providers are unaffected.

Ported from upstream PR (decolua/9router#1366).

Co-authored-by: nguyenha935 <nguyenha935@users.noreply.github.com>
@diegosouzapw
diegosouzapw force-pushed the feat/port-pr-1366-gemini-embedding-dimensions branch from a08d7b8 to 0d5d992 Compare June 20, 2026 23:23
@diegosouzapw
diegosouzapw merged commit bda88db into release/v3.8.32 Jun 20, 2026
4 checks passed
@diegosouzapw
diegosouzapw deleted the feat/port-pr-1366-gemini-embedding-dimensions branch June 21, 2026 12:33
tkgo11 pushed a commit to tkgo11/OmniRoute that referenced this pull request Sep 23, 2026
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.

1 participant