Skip to content
Open
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
5 changes: 3 additions & 2 deletions conf/openmetadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -706,15 +706,16 @@ 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}
bedrock:
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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
}
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<LlmConfigHolder> 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<LlmConfigHolder> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading