.Net: feat: Add support for dimensions in Vertex AI embedding services#13612
Open
abbottdev wants to merge 1 commit intomicrosoft:mainfrom
Open
.Net: feat: Add support for dimensions in Vertex AI embedding services#13612abbottdev wants to merge 1 commit intomicrosoft:mainfrom
abbottdev wants to merge 1 commit intomicrosoft:mainfrom
Conversation
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.
Motivation and Context
Why is this change required?
PR #10489 added support for configuring embedding [dimensions] (outputDimensionality) for the Google AI connector, but the equivalent Vertex AI connector was not updated. This means specifying [Dimensions] in [EmbeddingGenerationOptions] or via the constructor has no effect when using Vertex AI — the API always returns the model's default dimensionality.
What problem does it solve?
When using [VertexAIEmbeddingGenerator] or [VertexAITextEmbeddingGenerationService]with a [dimensions] value (e.g. 128), the output embedding length is the model default (e.g. 3072) instead of the requested size.
What scenario does it contribute to?
Users who need to control embedding dimensionality for storage optimization, performance, or compatibility with downstream systems when using the Vertex AI endpoint.
Fixes: #12988
Description
This PR adds outputDimensionality support to the Vertex AI embedding connector, mirroring the existing Google AI implementation from PR #10489.
The Google connector has two parallel embedding paths — Google AI (uses API key, calls generativelanguage.googleapis.com) and Vertex AI (uses bearer token, calls [{location}-aiplatform.googleapis.com]). PR #10489 only wired up dimensions for the Google AI path. This PR applies the same pattern to every layer of the Vertex AI path.
The key structural difference between the two APIs is where outputDimensionality goes in the request JSON:
Google AI puts it per-content-item:
{ "requests": [{ "content": {...}, "outputDimensionality": 128 }] }Vertex AI puts it in the shared parameters block:
{ "instances": [...], "parameters": { "autoTruncate": false, "outputDimensionality": 128 } }The implementation follows this difference. In [VertexAIEmbeddingRequest], outputDimensionality is added to the existing [RequestParameters] class (alongside autoTruncate), rather than on each instance item.
Dimensions flow through the same chain as Google AI:
All new parameters default to null, preserving full backward compatibility.
Contribution Checklist