.Net: feat: Add support for dimensions in Vertex AI embedding services#13612
.Net: feat: Add support for dimensions in Vertex AI embedding services#13612westey-m merged 15 commits intomicrosoft:mainfrom
Conversation
|
@moonbox3 - any chance we can get some reviews on this PR? |
There was a problem hiding this comment.
Pull request overview
Adds support for configuring embedding output dimensionality (“dimensions” / outputDimensionality) for Vertex AI embedding connectors, matching the existing Google AI connector behavior and ensuring request-time options can override constructor defaults.
Changes:
- Thread
dimensionsthrough Vertex AI DI/kernel-builder extensions, generator/service constructors, and client request creation. - Add
outputDimensionalityto Vertex AI requestparametersJSON and omit it when null. - Add unit tests validating metadata/attributes and request payload inclusion/omission.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/src/Connectors/Connectors.Google/Services/VertexAITextEmbeddingGenerationService.cs | Adds dimensions constructor option, attributes metadata, and an overload accepting EmbeddingGenerationOptions. |
| dotnet/src/Connectors/Connectors.Google/Services/VertexAIEmbeddingGenerator.cs | Plumbs dimensions through generator constructors into the service. |
| dotnet/src/Connectors/Connectors.Google/Extensions/VertexAIServiceCollectionExtensions.cs | Adds dimensions optional parameter to DI registration helpers for embedding generation. |
| dotnet/src/Connectors/Connectors.Google/Extensions/VertexAIServiceCollectionExtensions.DependencyInjection.cs | Adds dimensions optional parameter to embedding generator registration overloads. |
| dotnet/src/Connectors/Connectors.Google/Extensions/VertexAIKernelBuilderExtensions.cs | Adds dimensions to kernel builder extension methods and forwards into service collection registration. |
| dotnet/src/Connectors/Connectors.Google/Core/VertexAI/VertexAIEmbeddingRequest.cs | Adds outputDimensionality under parameters in the Vertex AI request model. |
| dotnet/src/Connectors/Connectors.Google/Core/VertexAI/VertexAIEmbeddingClient.cs | Stores default dimensions and resolves final value from options?.Dimensions ?? _dimensions. |
| dotnet/src/Connectors/Connectors.Google.UnitTests/Services/VertexAITextEmbeddingGenerationServiceTests.cs | Adds tests for dimensions attributes and request serialization behavior. |
| dotnet/src/Connectors/Connectors.Google.UnitTests/Services/VertexAIEmbeddingGeneratorTests.cs | Adds tests for generator metadata and request serialization behavior with dimensions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
dotnet/src/Connectors/Connectors.Google/Services/VertexAITextEmbeddingGenerationService.cs
Show resolved
Hide resolved
...nnectors/Connectors.Google.UnitTests/Services/VertexAITextEmbeddingGenerationServiceTests.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Connectors/Connectors.Google/Core/VertexAI/VertexAIEmbeddingClient.cs
Show resolved
Hide resolved
...nnectors/Connectors.Google.UnitTests/Services/VertexAITextEmbeddingGenerationServiceTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: abbottdev <3226335+abbottdev@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds support for specifying embedding output dimensionality (outputDimensionality) for the Vertex AI embedding connector in the .NET Google connectors, aligning behavior with the existing Google AI embedding path and enabling constructor defaults + per-request overrides.
Changes:
- Plumbs optional
dimensionsthrough Vertex AI embedding DI/builder APIs and service/generator constructors. - Adds
outputDimensionalityto the Vertex AI embeddings request payload under the sharedparametersblock and resolves precedence (options.Dimensionsover constructor default). - Adds/extends unit tests to verify request JSON behavior and override precedence.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/src/Connectors/Connectors.Google/Services/VertexAITextEmbeddingGenerationService.cs | Adds dimensions constructor parameter, stores attributes, and introduces an overload accepting EmbeddingGenerationOptions. |
| dotnet/src/Connectors/Connectors.Google/Services/VertexAIEmbeddingGenerator.cs | Updates generator to accept dimensions and to pass options down for request-time override support. |
| dotnet/src/Connectors/Connectors.Google/Extensions/VertexAIServiceCollectionExtensions.cs | Adds dimensions parameter to obsolete embedding-generation registration overloads. |
| dotnet/src/Connectors/Connectors.Google/Extensions/VertexAIServiceCollectionExtensions.DependencyInjection.cs | Adds dimensions parameter to embedding generator DI registrations. |
| dotnet/src/Connectors/Connectors.Google/Extensions/VertexAIKernelBuilderExtensions.cs | Adds dimensions parameter to kernel builder extension methods and forwards it through. |
| dotnet/src/Connectors/Connectors.Google/Core/VertexAI/VertexAIEmbeddingRequest.cs | Adds outputDimensionality to request parameters and exposes it via FromData(..., dimensions). |
| dotnet/src/Connectors/Connectors.Google/Core/VertexAI/VertexAIEmbeddingClient.cs | Stores default dimensions and applies options.Dimensions ?? _dimensions when building requests. |
| dotnet/src/Connectors/Connectors.Google.UnitTests/Services/VertexAITextEmbeddingGenerationServiceTests.cs | Adds tests verifying attributes, request JSON omission/inclusion, and override precedence. |
| dotnet/src/Connectors/Connectors.Google.UnitTests/Services/VertexAIEmbeddingGeneratorTests.cs | Adds tests verifying metadata dimensions and request JSON behavior/override precedence via generator. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
dotnet/src/Connectors/Connectors.Google/Services/VertexAIEmbeddingGenerator.cs
Show resolved
Hide resolved
dotnet/src/Connectors/Connectors.Google/Services/VertexAITextEmbeddingGenerationService.cs
Outdated
Show resolved
Hide resolved
…L doc remark Co-authored-by: abbottdev <3226335+abbottdev@users.noreply.github.com>
…bedding generator.
|
Just re-ran dotnet format and saw a namespace ordering issue - I saw a build failure that looks like its due to the format step failing: |
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