Repository navigation
fix(embeddings): forward output dimensions to Gemini for consistent embedding dims - #4449
Merged
diegosouzapw merged 1 commit intoJun 20, 2026
Conversation
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
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
force-pushed
the
feat/port-pr-1366-gemini-embedding-dimensions
branch
from
June 20, 2026 23:23
a08d7b8 to
0d5d992
Compare
tkgo11
pushed a commit
to tkgo11/OmniRoute
that referenced
this pull request
Sep 23, 2026
Integrated into release/v3.8.32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Forward the OpenAI-style
dimensionsrequest field to the Gemini-nativeoutputDimensionalityfield so clients can reliably get the embeddingvector 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-compatibleclients typically request a smaller size (e.g. 1536 for
pgvectorschemas)via the OpenAI
dimensionsfield. OmniRoute already forwardeddimensionstoGemini's OpenAI-compatibility endpoint (
/v1beta/openai/embeddings), butGoogle's compatibility shim does not document the
dimensions→outputDimensionalitytranslation — so callers still received full-sizevectors back. The upstream PR fixes the same gap on the native
:embedContent/
:batchEmbedContentspath; this port applies the equivalent fix toOmniRoute's OpenAI-compat embeddings handler.
What changed
open-sse/handlers/embeddings.ts— whenprovider === "gemini"and theclient sent a positive finite
dimensions, mirror it into theoutputDimensionalityfield of the upstream body (alongside the existingdimensionsforwarding).0,NaN, negative values are ignored. Otherproviders 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 (
0rejected).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→ cleanAttribution
Original author: @nguyenha935 (upstream
decolua/9router#1366).