Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
</ItemGroup>
<!-- Semantic Kernel -->
<ItemGroup>
<PackageVersion Include="Microsoft.SemanticKernel" Version="1.10.0" />
<PackageVersion Include="Microsoft.SemanticKernel.Abstractions" Version="1.10.0" />
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.OpenAI" Version="1.10.0" />
<PackageVersion Include="Microsoft.SemanticKernel" Version="1.11.1" />
<PackageVersion Include="Microsoft.SemanticKernel.Abstractions" Version="1.11.1" />
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.OpenAI" Version="1.11.1" />
</ItemGroup>
<!-- Documentation -->
<ItemGroup>
Expand Down
12 changes: 12 additions & 0 deletions extensions/AzureOpenAI/AzureOpenAIConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ public enum APITypes
/// </summary>
public int MaxRetries { get; set; } = 10;

/// <summary>
/// The number of dimensions output embeddings should have.
/// Only supported in "text-embedding-3" and later models developed with
/// MRL, see https://arxiv.org/abs/2205.13147
/// </summary>
public int? EmbeddingDimensions { get; set; }

/// <summary>
/// Set credentials manually from code
/// </summary>
Expand Down Expand Up @@ -120,5 +127,10 @@ public void Validate()
{
throw new ConfigurationException($"Azure OpenAI: {nameof(this.MaxTokenTotal)} cannot be less than 1");
}

if (this.EmbeddingDimensions is < 1)
{
throw new ConfigurationException($"Azure OpenAI: {nameof(this.EmbeddingDimensions)} cannot be less than 1");
}
}
}
9 changes: 6 additions & 3 deletions extensions/AzureOpenAI/AzureOpenAITextEmbeddingGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public AzureOpenAITextEmbeddingGenerator(
modelId: config.Deployment,
endpoint: config.Endpoint,
credential: new DefaultAzureCredential(),
httpClient: httpClient);
httpClient: httpClient,
dimensions: config.EmbeddingDimensions);
break;

case AzureOpenAIConfig.AuthTypes.ManualTokenCredential:
Expand All @@ -67,7 +68,8 @@ public AzureOpenAITextEmbeddingGenerator(
modelId: config.Deployment,
endpoint: config.Endpoint,
credential: config.GetTokenCredential(),
httpClient: httpClient);
httpClient: httpClient,
dimensions: config.EmbeddingDimensions);
break;

case AzureOpenAIConfig.AuthTypes.APIKey:
Expand All @@ -76,7 +78,8 @@ public AzureOpenAITextEmbeddingGenerator(
modelId: config.Deployment,
endpoint: config.Endpoint,
apiKey: config.APIKey,
httpClient: httpClient);
httpClient: httpClient,
dimensions: config.EmbeddingDimensions);
break;

default:
Expand Down
12 changes: 12 additions & 0 deletions extensions/OpenAI/OpenAIConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ public enum TextGenerationTypes
/// </summary>
public int MaxRetries { get; set; } = 10;

/// <summary>
/// The number of dimensions output embeddings should have.
/// Only supported in "text-embedding-3" and later models developed with
/// MRL, see https://arxiv.org/abs/2205.13147
/// </summary>
public int? EmbeddingDimensions { get; set; }

/// <summary>
/// Verify that the current state is valid.
/// </summary>
Expand All @@ -87,5 +94,10 @@ public void Validate()
{
throw new ConfigurationException($"OpenAI: {nameof(this.EmbeddingModelMaxTokenTotal)} cannot be less than 1");
}

if (this.EmbeddingDimensions is < 1)
{
throw new ConfigurationException($"OpenAI: {nameof(this.EmbeddingDimensions)} cannot be less than 1");
}
}
}
9 changes: 6 additions & 3 deletions extensions/OpenAI/OpenAITextEmbeddingGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public OpenAITextEmbeddingGenerator(
this._client = new OpenAITextEmbeddingGenerationService(
modelId: config.EmbeddingModel,
openAIClient: openAIClient,
loggerFactory: loggerFactory);
loggerFactory: loggerFactory,
dimensions: config.EmbeddingDimensions);
}

/// <summary>
Expand Down Expand Up @@ -99,7 +100,8 @@ public OpenAITextEmbeddingGenerator(
this._client = new OpenAITextEmbeddingGenerationService(
modelId: config.EmbeddingModel,
openAIClient: OpenAIClientBuilder.BuildOpenAIClient(config, httpClient),
loggerFactory: loggerFactory);
loggerFactory: loggerFactory,
dimensions: config.EmbeddingDimensions);
}

/// <summary>
Expand All @@ -123,7 +125,8 @@ public OpenAITextEmbeddingGenerator(

this._client = new OpenAITextEmbeddingGenerationService(
modelId: config.EmbeddingModel,
openAIClient: OpenAIClientBuilder.BuildOpenAIClient(config, httpClient));
openAIClient: OpenAIClientBuilder.BuildOpenAIClient(config, httpClient),
dimensions: config.EmbeddingDimensions);
}

/// <inheritdoc/>
Expand Down
12 changes: 10 additions & 2 deletions service/Service/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,11 @@
"Deployment": "",
// The max number of tokens supported by model deployed
// See https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models
"MaxTokenTotal": 8191
"MaxTokenTotal": 8191,
// The number of dimensions output embeddings should have.
// Only supported in "text-embedding-3" and later models developed with
// MRL, see https://arxiv.org/abs/2205.13147
"EmbeddingDimensions": null
},
"AzureOpenAIText": {
// "ApiKey" or "AzureIdentity"
Expand Down Expand Up @@ -352,7 +356,11 @@
// Change this to use proxies or services compatible with OpenAI HTTP protocol like LM Studio.
"Endpoint": "",
// How many times to retry in case of throttling
"MaxRetries": 10
"MaxRetries": 10,
// The number of dimensions output embeddings should have.
// Only supported in "text-embedding-3" and later models developed with
// MRL, see https://arxiv.org/abs/2205.13147
"EmbeddingDimensions": null
},
"Postgres": {
// Postgres instance connection string
Expand Down