diff --git a/conf/openmetadata.yaml b/conf/openmetadata.yaml index 069ca287e906..24d68a6d5c25 100644 --- a/conf/openmetadata.yaml +++ b/conf/openmetadata.yaml @@ -706,8 +706,8 @@ llmConfiguration: baseUrl: ${LLM_ANTHROPIC_BASE_URL:-"https://api.anthropic.com"} maxTokens: ${LLM_ANTHROPIC_MAX_TOKENS:-4096} # Vector embeddings for semantic search. Credentials reuse the provider blocks above - # (bedrock.awsConfig, openai.apiKey/endpoint, google.apiKey); this section only selects the - # embedding provider + model. The embedding provider may differ from the chat provider above. + # (bedrock.awsConfig, openai.apiKey/endpoint, google.apiKey). The embedding provider may differ + # from the chat provider above. embeddings: provider: ${EMBEDDING_PROVIDER:-bedrock} # bedrock | openai | google | djl maxConcurrentRequests: ${MAX_CONCURRENT_EMBEDDING_REQUESTS:-10} @@ -715,6 +715,7 @@ llmConfiguration: embeddingModelId: ${AWS_BEDROCK_EMBED_MODEL_ID:-"amazon.titan-embed-text-v2:0"} embeddingDimension: ${AWS_BEDROCK_EMBEDDING_DIMENSION:-512} openai: + deploymentName: ${OPENAI_EMBEDDING_DEPLOYMENT:-""} # Azure: requires LLM_OPENAI_ENDPOINT when set embeddingModelId: ${OPENAI_EMBEDDING_MODEL_ID:-"text-embedding-3-small"} embeddingDimension: ${OPENAI_EMBEDDING_DIMENSION:-1536} google: diff --git a/docs/decisions/2026-11-27-azure-embeddings-can-select-their-own-deployment.md b/docs/decisions/2026-11-27-azure-embeddings-can-select-their-own-deployment.md new file mode 100644 index 000000000000..692e54b4c3b6 --- /dev/null +++ b/docs/decisions/2026-11-27-azure-embeddings-can-select-their-own-deployment.md @@ -0,0 +1,19 @@ +# Azure embeddings can select their own deployment + +- **Status:** Accepted +- **Revisions:** v1 2026-11-27 (initial) +- **Deciders:** OpenMetadata contributors +- **Guard:** `OpenAIEmbeddingClientTest.routesChatAndEmbeddings` and `SystemRepositoryEmbeddingsValidationTest.reportsEmbeddingDeploymentWhenInitializationFails` +- **Related:** [#32196](https://github.com/open-metadata/OpenMetadata/issues/32196) + +## Context + +Azure puts the deployment name in the request URL. Chat and embedding models can have separate deployment names on the same endpoint. Sending an embedding request to a chat deployment prevents semantic search from indexing or retrieving vectors. + +## Decision + +For an Azure endpoint, embedding requests use `llmConfiguration.embeddings.openai.deploymentName` when set. A missing or blank value falls back to `llmConfiguration.openai.deploymentName`. Chat continues to use the latter. An explicit embedding deployment requires a nonblank `llmConfiguration.openai.endpoint` (`LLM_OPENAI_ENDPOINT`). The client rejects this incomplete configuration before opening a connection, and setup validation identifies the missing endpoint. For valid Azure configurations, validation reports the deployment used for embeddings. + +## Consequences + +Existing single-deployment configurations continue to work. Operators can route semantic search independently with `OPENAI_EMBEDDING_DEPLOYMENT` while sharing the endpoint, API version and credentials. OpenAI-compatible endpoints with both names unset keep their existing embeddings route and bearer authentication. diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/SystemRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/SystemRepository.java index 70ceaaeba7c9..e98920253a93 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/SystemRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/SystemRepository.java @@ -132,6 +132,7 @@ import org.openmetadata.service.search.SearchHealthStatus; import org.openmetadata.service.search.SearchRepository; import org.openmetadata.service.search.vector.client.EmbeddingClient; +import org.openmetadata.service.search.vector.client.OpenAIEmbeddingClient; import org.openmetadata.service.secrets.masker.PasswordEntityMasker; import org.openmetadata.service.security.AuthenticationCodeFlowHandler; import org.openmetadata.service.security.Authorizer; @@ -1569,21 +1570,25 @@ private String getOpenAiEmbeddingMessage( String message = "OpenAI provider selected but openai configuration block is missing"; if (embeddings.getOpenai() != null) { LLMOpenAIConfig openaiCreds = llmConfig.getOpenai(); - String openaiEndpoint = - openaiCreds == null || nullOrEmpty(openaiCreds.getEndpoint()) - ? "api.openai.com" - : openaiCreds.getEndpoint(); - String deploymentInfo = - openaiCreds == null || nullOrEmpty(openaiCreds.getDeploymentName()) - ? "" - : String.format(", deploymentName: %s", openaiCreds.getDeploymentName()); - message = - String.format( - "OpenAI configuration: endpoint: %s, embeddingModelId: %s, embeddingDimension: %s%s", - openaiEndpoint, - embeddings.getOpenai().getEmbeddingModelId(), - embeddings.getOpenai().getEmbeddingDimension(), - deploymentInfo); + try { + String deploymentName = + OpenAIEmbeddingClient.azureDeploymentName(openaiCreds, embeddings.getOpenai()); + String openaiEndpoint = + openaiCreds == null || nullOrEmpty(openaiCreds.getEndpoint()) + ? "api.openai.com" + : openaiCreds.getEndpoint(); + String deploymentInfo = + deploymentName == null ? "" : String.format(", deploymentName: %s", deploymentName); + message = + String.format( + "OpenAI configuration: endpoint: %s, embeddingModelId: %s, embeddingDimension: %s%s", + openaiEndpoint, + embeddings.getOpenai().getEmbeddingModelId(), + embeddings.getOpenai().getEmbeddingDimension(), + deploymentInfo); + } catch (IllegalArgumentException invalidConfiguration) { + message = invalidConfiguration.getMessage(); + } } return message; } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/OpenAIEmbeddingClient.java b/openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/OpenAIEmbeddingClient.java index fb7b0b37a740..ca1708f12eab 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/OpenAIEmbeddingClient.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/search/vector/client/OpenAIEmbeddingClient.java @@ -11,6 +11,7 @@ import java.net.http.HttpResponse; import java.time.Duration; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.openmetadata.schema.configuration.LLMConfiguration; import org.openmetadata.schema.configuration.LLMOpenAIConfig; import org.openmetadata.schema.configuration.LLMOpenAIEmbeddingConfig; @@ -33,6 +34,7 @@ public OpenAIEmbeddingClient(LLMConfiguration config) { LLMOpenAIEmbeddingConfig embeddingCfg = config.getEmbeddings() != null ? config.getEmbeddings().getOpenai() : null; LLMOpenAIConfig openaiCfg = config.getOpenai(); + String deploymentName = azureDeploymentName(openaiCfg, embeddingCfg); if (embeddingCfg == null || openaiCfg == null) { throw new IllegalArgumentException("OpenAI configuration is required"); } @@ -52,19 +54,21 @@ public OpenAIEmbeddingClient(LLMConfiguration config) { this.dimension = embeddingCfg.getEmbeddingDimension(); String endpoint = openaiCfg.getEndpoint(); - String deploymentName = openaiCfg.getDeploymentName(); - boolean hasEndpoint = endpoint != null && !endpoint.isBlank(); - boolean hasDeployment = deploymentName != null && !deploymentName.isBlank(); - - this.isAzure = hasEndpoint && hasDeployment; - - if (this.isAzure - && (openaiCfg.getApiVersion() == null || openaiCfg.getApiVersion().isBlank())) { + this.isAzure = deploymentName != null; + if (isAzure && StringUtils.isBlank(openaiCfg.getApiVersion())) { throw new IllegalArgumentException( "Azure API version is required for Azure OpenAI deployments"); } - this.endpoint = resolveEndpoint(openaiCfg); + String base = + StringUtils.stripEnd( + StringUtils.defaultIfBlank(endpoint, "https://api.openai.com/v1"), "/"); + this.endpoint = + isAzure + ? String.format( + "%s/openai/deployments/%s/embeddings?api-version=%s", + base, deploymentName, openaiCfg.getApiVersion()) + : base + "/embeddings"; this.httpClient = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(30)).build(); LOG.info( @@ -103,23 +107,18 @@ public OpenAIEmbeddingClient(LLMConfiguration config) { this.isAzure = isAzure; } - private String resolveEndpoint(LLMOpenAIConfig config) { - String endpoint = config.getEndpoint(); - String deploymentName = config.getDeploymentName(); - boolean hasEndpoint = endpoint != null && !endpoint.isBlank(); - boolean hasDeployment = deploymentName != null && !deploymentName.isBlank(); - - if (hasEndpoint && hasDeployment) { - String base = endpoint.replaceAll("/+$", ""); - return String.format( - "%s/openai/deployments/%s/embeddings?api-version=%s", - base, deploymentName, config.getApiVersion()); - } - if (hasEndpoint) { - String base = endpoint.replaceAll("/+$", ""); - return base + "/embeddings"; + /** The deployment used by embedding requests and reported by setup validation. */ + public static String azureDeploymentName( + LLMOpenAIConfig openai, LLMOpenAIEmbeddingConfig embeddings) { + boolean hasEndpoint = openai != null && StringUtils.isNotBlank(openai.getEndpoint()); + String override = embeddings == null ? null : embeddings.getDeploymentName(); + if (StringUtils.isNotBlank(override) && !hasEndpoint) { + throw new IllegalArgumentException( + "Set llmConfiguration.openai.endpoint (LLM_OPENAI_ENDPOINT) when configuring an Azure embedding deployment."); } - return "https://api.openai.com/v1/embeddings"; + return hasEndpoint && embeddings != null + ? StringUtils.firstNonBlank(override, openai.getDeploymentName()) + : null; } @Override diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/jdbi3/SystemRepositoryEmbeddingsValidationTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/jdbi3/SystemRepositoryEmbeddingsValidationTest.java index 727820954cc2..8854db1f152b 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/jdbi3/SystemRepositoryEmbeddingsValidationTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/jdbi3/SystemRepositoryEmbeddingsValidationTest.java @@ -10,12 +10,20 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullAndEmptySource; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.MockedStatic; +import org.openmetadata.schema.configuration.LLMConfiguration; +import org.openmetadata.schema.configuration.LLMEmbeddingsConfig; +import org.openmetadata.schema.configuration.LLMOpenAIConfig; +import org.openmetadata.schema.configuration.LLMOpenAIEmbeddingConfig; import org.openmetadata.schema.service.configuration.elasticsearch.ElasticSearchConfiguration; import org.openmetadata.schema.service.configuration.elasticsearch.NaturalLanguageSearchConfiguration; import org.openmetadata.schema.system.StepValidation; import org.openmetadata.service.Entity; import org.openmetadata.service.OpenMetadataApplicationConfig; +import org.openmetadata.service.clients.llm.LlmConfigHolder; import org.openmetadata.service.jdbi3.SystemTokenDAOs.SystemDAO; import org.openmetadata.service.migration.MigrationValidationClient; import org.openmetadata.service.search.SearchRepository; @@ -117,6 +125,50 @@ void testPipelineCheck5xxReportsSpecificError() { assertTrue(result.getMessage().contains("Unexpected status 500")); } + @Test + void reportsEmbeddingDeploymentWhenInitializationFails() { + LLMConfiguration config = + new LLMConfiguration() + .withOpenai( + new LLMOpenAIConfig() + .withEndpoint("https://example.com") + .withDeploymentName("chat")) + .withEmbeddings( + new LLMEmbeddingsConfig() + .withProvider(LLMEmbeddingsConfig.Provider.OPENAI) + .withOpenai(new LLMOpenAIEmbeddingConfig().withDeploymentName("vectors"))); + try (MockedStatic holder = mockStatic(LlmConfigHolder.class)) { + holder.when(LlmConfigHolder::get).thenReturn(config); + + StepValidation result = systemRepository.getEmbeddingsValidation(appConfig); + + assertFalse(result.getPassed()); + assertTrue(result.getMessage().contains("deploymentName: vectors"), result.getMessage()); + } + } + + @ParameterizedTest + @NullAndEmptySource + @ValueSource(strings = {" "}) + void reportsMissingEndpointForAnEmbeddingDeployment(String endpoint) { + LLMConfiguration config = + new LLMConfiguration() + .withOpenai(new LLMOpenAIConfig().withEndpoint(endpoint)) + .withEmbeddings( + new LLMEmbeddingsConfig() + .withProvider(LLMEmbeddingsConfig.Provider.OPENAI) + .withOpenai(new LLMOpenAIEmbeddingConfig().withDeploymentName("vectors"))); + try (MockedStatic holder = mockStatic(LlmConfigHolder.class)) { + holder.when(LlmConfigHolder::get).thenReturn(config); + + StepValidation result = systemRepository.getEmbeddingsValidation(appConfig); + + assertFalse(result.getPassed()); + assertTrue(result.getMessage().contains("LLM_OPENAI_ENDPOINT"), result.getMessage()); + assertFalse(result.getMessage().contains("api.openai.com"), result.getMessage()); + } + } + @Test void testEmbeddingClientInitFailureIncludesErrorMessage() { when(searchRepository.getVectorIndexService()).thenReturn(null); diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/search/vector/client/OpenAIEmbeddingClientTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/search/vector/client/OpenAIEmbeddingClientTest.java index a9b020152b5a..bb37c4cc1b91 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/search/vector/client/OpenAIEmbeddingClientTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/search/vector/client/OpenAIEmbeddingClientTest.java @@ -6,11 +6,16 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpServer; +import java.io.IOException; +import java.net.InetSocketAddress; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpHeaders; import java.net.http.HttpRequest; import java.net.http.HttpResponse; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -23,10 +28,15 @@ import java.util.concurrent.atomic.AtomicReference; import javax.net.ssl.SSLSession; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.NullAndEmptySource; +import org.junit.jupiter.params.provider.ValueSource; import org.openmetadata.schema.configuration.LLMConfiguration; import org.openmetadata.schema.configuration.LLMEmbeddingsConfig; import org.openmetadata.schema.configuration.LLMOpenAIConfig; import org.openmetadata.schema.configuration.LLMOpenAIEmbeddingConfig; +import org.openmetadata.service.llm.OpenAICompletionClient; import org.openmetadata.service.search.vector.client.EmbeddingClient.EmbeddingUsage; class OpenAIEmbeddingClientTest { @@ -183,26 +193,72 @@ void testClientCreationWithCustomModel() { assertEquals("text-embedding-ada-002", client.getModelId()); } - @Test - void testAzureEndpointResolution() { - LLMConfiguration config = - new LLMConfiguration() - .withOpenai( - new LLMOpenAIConfig() - .withApiKey("test-key") - .withEndpoint("https://my-resource.openai.azure.com") - .withDeploymentName("my-deployment") - .withApiVersion("2024-02-01")) - .withEmbeddings( - new LLMEmbeddingsConfig() - .withProvider(LLMEmbeddingsConfig.Provider.OPENAI) - .withOpenai( - new LLMOpenAIEmbeddingConfig() - .withEmbeddingModelId("text-embedding-3-small") - .withEmbeddingDimension(1536))); + @ParameterizedTest + @CsvSource({ + "chat, vectors, /openai/deployments/chat/chat/completions, /openai/deployments/vectors/embeddings", + "shared, , /openai/deployments/shared/chat/completions, /openai/deployments/shared/embeddings", + "shared, ' ', /openai/deployments/shared/chat/completions, /openai/deployments/shared/embeddings", + ", vectors, /chat/completions, /openai/deployments/vectors/embeddings", + ", , /chat/completions, /embeddings" + }) + void routesChatAndEmbeddings( + String chatDeployment, String embeddingDeployment, String chatPath, String embeddingPath) + throws IOException { + HttpServer server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0); + server.createContext( + chatPath, + exchange -> + serveProviderResponse( + exchange, chatPath, "{\"choices\":[{\"message\":{\"content\":\"ok\"}}]}")); + server.createContext( + embeddingPath, + exchange -> + serveProviderResponse(exchange, embeddingPath, "{\"data\":[{\"embedding\":[0.5]}]}")); + server.start(); + try { + LLMConfiguration config = buildConfig("test-key", "text-embedding-3-small", 1); + config + .getOpenai() + .withEndpoint("http://127.0.0.1:" + server.getAddress().getPort() + "/") + .withDeploymentName(chatDeployment) + .withApiVersion("2024-02-01"); + config.getEmbeddings().getOpenai().setDeploymentName(embeddingDeployment); + + assertEquals("ok", new OpenAICompletionClient(config).complete("system", "prompt").text()); + assertEquals(0.5f, new OpenAIEmbeddingClient(config).embed("input")[0]); + } finally { + server.stop(0); + } + } - OpenAIEmbeddingClient client = new OpenAIEmbeddingClient(config); - assertNotNull(client); + private static void serveProviderResponse(HttpExchange exchange, String path, String response) + throws IOException { + try (exchange) { + boolean azure = path.startsWith("/openai/deployments/"); + String uri = azure ? path + "?api-version=2024-02-01" : path; + String credential = + exchange.getRequestHeaders().getFirst(azure ? "api-key" : "Authorization"); + boolean accepted = + exchange.getRequestURI().toString().equals(uri) + && (azure ? "test-key" : "Bearer test-key").equals(credential); + byte[] body = response.getBytes(StandardCharsets.UTF_8); + exchange.sendResponseHeaders(accepted ? 200 : 400, body.length); + exchange.getResponseBody().write(body); + } + } + + @ParameterizedTest + @NullAndEmptySource + @ValueSource(strings = {" "}) + void rejectsEmbeddingDeploymentWithoutEndpoint(String endpoint) { + LLMConfiguration config = buildConfig("test-key", "text-embedding-3-small", 1); + config.getOpenai().setEndpoint(endpoint); + config.getEmbeddings().getOpenai().setDeploymentName("vectors"); + + IllegalArgumentException error = + assertThrows(IllegalArgumentException.class, () -> new OpenAIEmbeddingClient(config)); + + assertTrue(error.getMessage().contains("LLM_OPENAI_ENDPOINT"), error.getMessage()); } @Test diff --git a/openmetadata-spec/src/main/resources/json/schema/configuration/llmConfiguration.json b/openmetadata-spec/src/main/resources/json/schema/configuration/llmConfiguration.json index e2c10920d62e..fa39a43b4b03 100644 --- a/openmetadata-spec/src/main/resources/json/schema/configuration/llmConfiguration.json +++ b/openmetadata-spec/src/main/resources/json/schema/configuration/llmConfiguration.json @@ -132,6 +132,10 @@ "type": "object", "javaType": "org.openmetadata.schema.configuration.LLMOpenAIEmbeddingConfig", "properties": { + "deploymentName": { + "type": "string", + "description": "Azure OpenAI deployment for embeddings. Setting it requires llmConfiguration.openai.endpoint. When unset, uses the deploymentName from llmConfiguration.openai." + }, "embeddingModelId": { "type": "string", "default": "text-embedding-3-small" }, "embeddingDimension": { "type": "integer", "default": 1536 } }, diff --git a/openmetadata-ui/src/main/resources/ui/src/generated/configuration/llmConfiguration.ts b/openmetadata-ui/src/main/resources/ui/src/generated/configuration/llmConfiguration.ts index e9ef17d1b1be..188681ecfdfc 100644 --- a/openmetadata-ui/src/main/resources/ui/src/generated/configuration/llmConfiguration.ts +++ b/openmetadata-ui/src/main/resources/ui/src/generated/configuration/llmConfiguration.ts @@ -152,6 +152,12 @@ export interface EmbeddingsGoogle { } export interface EmbeddingsOpenai { + /** + * Azure OpenAI deployment for embeddings. Setting it requires + * llmConfiguration.openai.endpoint. When unset, uses the deploymentName from + * llmConfiguration.openai. + */ + deploymentName?: string; embeddingDimension?: number; embeddingModelId?: string; }