Configure automatic embedding with Azure OpenAI¶
Azure OpenAI uses the OPENAI_COMPATIBLE provider. It differs from the standard OpenAI endpoint in two ways:
- The endpoint is specific to an Azure OpenAI deployment and includes an
api-versionparameter. - Authentication uses the
api-keyheader rather thanAuthorization: Bearer.
Before you begin¶
Make sure that:
- Percona Server for MongoDB and Percona Search for MongoDB are configured and running.
- An embedding model is deployed to your Azure OpenAI resource.
- You know the Azure resource name.
- You know the deployment name.
- You have an Azure OpenAI API key.
- You know the API version supported by your deployment.
- The host running
mongotcan connect to Azure OpenAI.
Procedure¶
To configure automatic embedding with Azure OpenAI, do the following:
-
Verify the Azure endpoint.
Azure OpenAI uses a deployment-specific embedding endpoint:
https://<resource>.openai.azure.com/openai/deployments/<deployment>/embeddings?api-version=<api-version>-
Test the endpoint before configuring
mongot:curl "https://<resource>.openai.azure.com/openai/deployments/<deployment>/embeddings?api-version=<api-version>" \ -H "Content-Type: application/json" \ -H "api-key: <your-azure-openai-api-key>" \ -d '{ "model": "<deployment>", "input": "hello" }' -
A successful response contains an embedding vector.
-
-
Enable automatic embedding.
Add the
embeddingsection tomongot.conf:embedding: isAutoEmbeddingViewWriter: trueImportant
If multiple
mongotinstances process the same data, configure only one instance as the automatic embedding writer. -
Configure the model in the catalog.
Add an entry to
embedding-service-configs.ymlwith the Azure OpenAI endpoint and API key:configs: - modelName: text-embedding-3-small embeddingProvider: OPENAI_COMPATIBLE config: providerEndpoint: https://my-resource.openai.azure.com/openai/deployments/text-embedding-3-small/embeddings?api-version=2024-02-01 modelConfig: batchSize: 96 batchTokenLimit: 120000 outputDimensions: 1536 quantization: float forwardDimensions: true errorHandlingConfig: maxRetries: 10 initialRetryWaitMs: 200 maxRetryWaitMs: 10000 jitter: 0.1 credentials: apiKey: "<your-azure-openai-api-key>" authHeaderName: api-keyNote
Replace the resource name, deployment name, API version, and API key with values from your Azure OpenAI deployment.
-
Configure Azure authentication.
Standard OpenAI authentication uses:
Authorization: Bearer <key>Azure OpenAI uses:
api-key: <key>Configure the credentials as follows:
credentials: apiKey: "<your-azure-openai-api-key>" authHeaderName: api-keyWhen
authHeaderNameis set toapi-key,mongotsends the API key directly in that header without adding theBearerprefix. -
Configure vector dimensions.
If your Azure deployment uses a
text-embedding-3model, you can enable:forwardDimensions: trueThis allows
mongotto send the resolved vector dimension using the OpenAI-compatibledimensionsfield.For models that don’t support configurable dimensions, omit
forwardDimensionsor set it tofalse.Note
Make sure
outputDimensionsmatches the vector dimensions expected by the model and index configuration. -
Start and verify
mongot.Restart
mongotafter updating the model catalog:sudo systemctl restart mongotReview the logs for configuration, connectivity, or authentication errors.
Tips: Azure OpenAI connectivity issues
Work through these in order. The first three cover most failures.
- Authentication: The API key must be valid for the resource, and
authHeaderNamemust be set toapi-key. If the header name is missing or wrong, Azure rejects the request with HTTP 401 or 403, andmongotdoesn’t retry it. - Endpoint:
providerEndpointmust name the same resource and deployment you tested withcurlin step 1. - API version: The
api-versionparameter must be one your deployment supports. Azure rejects versions it doesn’t recognize. - Deployment name: The deployment named in the endpoint must exist in your Azure OpenAI resource, and the name is case-sensitive.
- Vector dimensions:
outputDimensionsmust match what the deployment actually returns, unlessforwardDimensionsis enabled. EnableforwardDimensionsonly for models that accept thedimensionsrequest field.