-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.Net: Support for configuring dimensions in Google AI embeddings generation #10489
base: main
Are you sure you want to change the base?
Conversation
Hi team, |
@microsoft-github-policy-service agree |
Hi team, |
/// </summary> | ||
/// <param name="service">The service from which to get the dimensions.</param> | ||
/// <returns>The dimensions if it was specified in the service's attributes; otherwise, null.</returns> | ||
public static int? GetDimensions(this IAIService service) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very specific for Embeddings
, not a good candidate to live in the IAIService
level. Consider changing it to ITextEmbeddingsGeneration
interface.
Same for the DimensionsKey
above.
public static int? GetDimensions(this IAIService service) |
|
||
// Assert | ||
Assert.Equal(model, service.Attributes[AIServiceExtensions.ModelIdKey]); | ||
Assert.Null(result); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add tests checking that the RequestContent
generated the right property
in the body before calling the API.
like:
Dimensions = null
don't findoutput_dimensionality
property in the requestDimensions = 2
should findoutput_dimensionality
property in the request with value = 2.
Similar to this:
Line 120 in 4fdaf67
public async Task GetUriImageContentsImageQualityRequestWorksCorrectlyAsync(string? quality, string? expectedQuality) |
Hi @ArieSLV thanks for you contributions, most of it looking good so far.
|
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