-
Notifications
You must be signed in to change notification settings - Fork 304
Add internal text embedding system #3113
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
base: main
Are you sure you want to change the base?
Changes from all commits
0dc589e
d3187bd
6064826
0653f15
21e81b9
0cd8e53
7fa1c49
c3f6937
1e18c25
857203a
89cb2d9
64b592e
e8d7238
d9c8a29
3e02c0f
5c05464
c9eba20
d3a5209
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| using Azure.DataApiBuilder.Config.Converters; | ||
| using Azure.DataApiBuilder.Config.NamingPolicies; | ||
| using Azure.DataApiBuilder.Config.ObjectModel; | ||
| using Azure.DataApiBuilder.Config.ObjectModel.Embeddings; | ||
| using Azure.DataApiBuilder.Core; | ||
| using Azure.DataApiBuilder.Core.Configurations; | ||
| using Azure.DataApiBuilder.Service; | ||
|
|
@@ -908,6 +909,27 @@ options.FileSinkRetainedFileCountLimit is not null || | |
| } | ||
| } | ||
|
|
||
| // Embeddings: Provider, Endpoint, ApiKey, Model, ApiVersion, Dimensions, TimeoutMs, Enabled | ||
| if (options.RuntimeEmbeddingsProvider is not null || | ||
| options.RuntimeEmbeddingsBaseUrl is not null || | ||
| options.RuntimeEmbeddingsApiKey is not null || | ||
| options.RuntimeEmbeddingsModel is not null || | ||
| options.RuntimeEmbeddingsApiVersion is not null || | ||
| options.RuntimeEmbeddingsDimensions is not null || | ||
| options.RuntimeEmbeddingsTimeoutMs is not null || | ||
| options.RuntimeEmbeddingsEnabled is not null) | ||
| { | ||
| bool status = TryUpdateConfiguredEmbeddingsValues(options, runtimeConfig?.Runtime?.Embeddings, out EmbeddingsOptions? updatedEmbeddingsOptions); | ||
| if (status && updatedEmbeddingsOptions is not null) | ||
| { | ||
| runtimeConfig = runtimeConfig! with { Runtime = runtimeConfig.Runtime! with { Embeddings = updatedEmbeddingsOptions } }; | ||
| } | ||
| else | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return runtimeConfig != null; | ||
| } | ||
|
|
||
|
|
@@ -1522,6 +1544,97 @@ private static bool TryUpdateConfiguredFileOptions( | |
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Attempts to update the embeddings configuration based on the provided options. | ||
| /// Creates a new EmbeddingsOptions object if the configuration is valid. | ||
| /// Provider, endpoint, and API key are required when configuring embeddings. | ||
| /// </summary> | ||
| /// <param name="options">The configuration options provided by the user.</param> | ||
| /// <param name="existingEmbeddingsOptions">The existing embeddings options from the runtime configuration.</param> | ||
| /// <param name="updatedEmbeddingsOptions">The resulting embeddings options if successful.</param> | ||
| /// <returns>True if the embeddings options were successfully configured; otherwise, false.</returns> | ||
| private static bool TryUpdateConfiguredEmbeddingsValues( | ||
| ConfigureOptions options, | ||
| EmbeddingsOptions? existingEmbeddingsOptions, | ||
| out EmbeddingsOptions? updatedEmbeddingsOptions) | ||
| { | ||
| updatedEmbeddingsOptions = null; | ||
|
|
||
| try | ||
| { | ||
| // Get values from options or fall back to existing configuration | ||
| EmbeddingProviderType? provider = options.RuntimeEmbeddingsProvider ?? existingEmbeddingsOptions?.Provider; | ||
| string? baseUrl = options.RuntimeEmbeddingsBaseUrl ?? existingEmbeddingsOptions?.BaseUrl; | ||
| string? apiKey = options.RuntimeEmbeddingsApiKey ?? existingEmbeddingsOptions?.ApiKey; | ||
| string? model = options.RuntimeEmbeddingsModel ?? existingEmbeddingsOptions?.Model; | ||
| string? apiVersion = options.RuntimeEmbeddingsApiVersion ?? existingEmbeddingsOptions?.ApiVersion; | ||
| int? dimensions = options.RuntimeEmbeddingsDimensions ?? existingEmbeddingsOptions?.Dimensions; | ||
| int? timeoutMs = options.RuntimeEmbeddingsTimeoutMs ?? existingEmbeddingsOptions?.TimeoutMs; | ||
| bool? enabled = options.RuntimeEmbeddingsEnabled.HasValue | ||
| ? options.RuntimeEmbeddingsEnabled.Value == CliBool.True | ||
| : existingEmbeddingsOptions?.Enabled; | ||
|
|
||
| // Validate required fields | ||
| if (provider is null) | ||
| { | ||
| _logger.LogError("Failed to configure embeddings: provider is required. Use --runtime.embeddings.provider to specify the provider (azure-openai or openai)."); | ||
| return false; | ||
| } | ||
|
|
||
| if (string.IsNullOrEmpty(baseUrl)) | ||
| { | ||
| _logger.LogError("Failed to configure embeddings: base-url is required. Use --runtime.embeddings.base-url to specify the provider base URL."); | ||
| return false; | ||
| } | ||
|
|
||
| if (string.IsNullOrEmpty(apiKey)) | ||
| { | ||
| _logger.LogError("Failed to configure embeddings: api-key is required. Use --runtime.embeddings.api-key to specify the authentication key."); | ||
| return false; | ||
| } | ||
|
|
||
| // Validate Azure OpenAI requires model/deployment name | ||
| if (provider == EmbeddingProviderType.AzureOpenAI && string.IsNullOrEmpty(model)) | ||
| { | ||
| _logger.LogError("Failed to configure embeddings: model/deployment name is required for Azure OpenAI provider. Use --runtime.embeddings.model to specify the deployment name."); | ||
| return false; | ||
| } | ||
|
|
||
| // Validate dimensions if provided | ||
| if (dimensions is not null && dimensions <= 0) | ||
| { | ||
| _logger.LogError("Failed to configure embeddings: dimensions must be a positive integer."); | ||
| return false; | ||
| } | ||
|
|
||
| // Validate timeout if provided | ||
| if (timeoutMs is not null && timeoutMs <= 0) | ||
| { | ||
| _logger.LogError("Failed to configure embeddings: timeout-ms must be a positive integer."); | ||
| return false; | ||
| } | ||
|
|
||
| // Create the embeddings options | ||
| updatedEmbeddingsOptions = new EmbeddingsOptions( | ||
| Provider: (EmbeddingProviderType)provider, | ||
| BaseUrl: baseUrl, | ||
| ApiKey: apiKey, | ||
|
Comment on lines
+1617
to
+1621
|
||
| Enabled: enabled, | ||
| Model: model, | ||
| ApiVersion: apiVersion, | ||
| Dimensions: dimensions, | ||
| TimeoutMs: timeoutMs); | ||
|
|
||
| _logger.LogInformation("Updated RuntimeConfig with Runtime.Embeddings configuration."); | ||
| return true; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _logger.LogError("Failed to update RuntimeConfig.Embeddings with exception message: {exceptionMessage}.", ex.Message); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Parse permission string to create PermissionSetting array. | ||
| /// </summary> | ||
|
|
||
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.
ConfigGeneratoronly triggers embeddings updates for provider/base-url/api-key/model/api-version/dimensions/timeout/enabled. The CLI also definesruntime.embeddings.endpoint.*andruntime.embeddings.health.*, but those flags are ignored here.Include the endpoint/health CLI flags in this condition so
dab configureactually updates them.