.Net: Support for configuring dimensions in Google AI embeddings generation #10489
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
This change addresses a limitation in the current implementation of the Google AI embeddings generation service in Semantic Kernel. Currently, users cannot configure the output dimensionality of the embeddings, even though the underlying Google AI API supports specifying the number of dimensions via the
output_dimensionality
parameter.Why is this change required?
Allowing configuration of the dimensions provides greater flexibility for users to tailor the embeddings to their specific use cases—whether for optimizing memory usage, improving performance, or ensuring compatibility with downstream systems that expect a particular embedding size.
What problem does it solve?
It solves the issue of inflexibility by exposing the
dimensions
parameter in the service constructors, builder methods, and API request payloads. This ensures that developers can leverage the full capabilities of the Google API without being limited to the default embedding size.What scenario does it contribute to?
This feature is particularly useful in scenarios where:
Relevant issue link: #10488
Description
This PR introduces support for specifying the output dimensionality in the Google AI embeddings generation workflow. The main changes include:
Service Constructor Update:
The
GoogleAITextEmbeddingGenerationService
constructor now accepts an optionaldimensions
parameter, which is then forwarded to the lower-level client implementations.Builder and Extension Methods:
Extension methods such as
AddGoogleAIEmbeddingGeneration
have been updated to accept adimensions
parameter. This allows developers to configure the embedding dimensions using the builder pattern.Request Payload Enhancement:
The
GoogleAIEmbeddingRequest
class now includes a new optional propertyDimensions
(serialized asoutput_dimensionality
). When provided, this value is included in the JSON payload sent to the Google AI API.Metadata and Attributes Update:
The service’s metadata now reflects the provided dimensions, ensuring consistency in configuration tracking.
Unit Testing:
New unit tests have been added to confirm that:
dimensions
value is provided, it is correctly included in the JSON request.This enhancement maintains backward compatibility since the new parameter is optional. Existing implementations that do not specify a dimension will continue to work as before.
Contribution Checklist