{"id":7081,"date":"2026-05-08T14:42:36","date_gmt":"2026-05-08T21:42:36","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/azure-sql\/?p=7081"},"modified":"2026-05-11T07:17:31","modified_gmt":"2026-05-11T14:17:31","slug":"generate-embeddings-function-and-external-model-object-support-are-now-generally-available-in-azure-sql","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/azure-sql\/generate-embeddings-function-and-external-model-object-support-are-now-generally-available-in-azure-sql\/","title":{"rendered":"Generate Embeddings Function and External Model Object Support Are Now Generally Available in Azure SQL"},"content":{"rendered":"<p>We are excited to announce the General Availability (GA) of\u00a0<a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/t-sql\/functions\/ai-generate-embeddings-transact-sql?view=sql-server-ver17\">AI_GENERATE_EMBEDDINGS<\/a>\u00a0and\u00a0<a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/t-sql\/statements\/create-external-model-transact-sql?view=sql-server-ver17\">CREATE EXTERNAL MODEL<\/a>\u00a0in\u00a0<strong>Azure SQL Database<\/strong>\u00a0and\u00a0<strong>Azure SQL Managed Instance<\/strong>.<\/p>\n<p>These two T-SQL features \u2014\u00a0<strong>CREATE EXTERNAL MODEL<\/strong>\u00a0and\u00a0<strong>AI_GENERATE_EMBEDDINGS<\/strong>\u00a0\u2014 work together as a single, integrated pipeline for generating vector embeddings directly from T-SQL. No data movement, no external orchestration, no application-layer pipeline required.<\/p>\n<p><strong>EXTERNAL MODEL object<\/strong>\u00a0defines\u00a0<strong>where<\/strong>\u00a0to get embeddings from and how to authenticate \u2014 registered once, reused everywhere.\u00a0<strong>AI_GENERATE_EMBEDDINGS<\/strong>\u00a0calls the external model to\u00a0<strong>generate<\/strong>\u00a0the vector arrays inline in any T-SQL statement. Developers then store those vectors in a\u00a0<a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/t-sql\/data-types\/vector-data-type?view=sql-server-ver17&amp;tabs=csharp\">VECTOR-typed<\/a>\u00a0column within a table and query them using\u00a0<a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/t-sql\/functions\/vector-distance-transact-sql?view=sql-server-ver17\">VECTOR_DISTANCE<\/a>\u00a0or\u00a0<a href=\"https:\/\/learn.microsoft.com\/en-us\/samples\/azure-samples\/azure-sql-db-openai\/azure-sql-db-openai\/\">VECTOR_SEARCH<\/a>\u00a0functions. Together, these capabilities form the foundation for Retrieval-Augmented Generation (RAG) and vector similarity search, built entirely within the SQL engine you are already familiar with.<\/p>\n<h2>Generating vector embeddings using an external AI model provider<\/h2>\n<p>Here is how\u00a0<strong>CREATE EXTERNAL MODEL<\/strong>\u00a0and\u00a0<strong>AI_GENERATE_EMBEDDINGS<\/strong>\u00a0connect in a single workflow:<\/p>\n<pre><code>-- Once: register your provider-specific REST endpoint as a named database object\r\nCREATE EXTERNAL MODEL MyEmbeddingModel\r\nWITH (LOCATION = '...', API_FORMAT = 'Azure OpenAI', MODEL_TYPE = EMBEDDINGS, MODEL = '...');\r\n\r\n-- Anywhere: generate embeddings inline in T-SQL\r\nUPDATE docs\r\nSET    docs.embedding = AI_GENERATE_EMBEDDINGS(docs.content USE MODEL MyEmbeddingModel)\r\nFROM   documents AS docs;<\/code><\/pre>\n<h3>CREATE EXTERNAL MODEL<\/h3>\n<p>CREATE EXTERNAL MODEL is a T-SQL DDL statement that creates a named object in the database storing the location, API format, model type, and authentication credential for an AI model inference endpoint. After the external model object is created, AI_GENERATE_EMBEDDINGS can use the external model object to generate embeddings.<\/p>\n<p>Syntax:<\/p>\n<pre><code>CREATE EXTERNAL MODEL external_model_object_name\r\n[ AUTHORIZATION owner_name ]\r\nWITH\r\n  ( LOCATION   = '&lt;prefix&gt;:\/\/&lt;path&gt;[:&lt;port&gt;]'\r\n  , API_FORMAT = 'Azure OpenAI | OpenAI'\r\n  , MODEL_TYPE = EMBEDDINGS\r\n  , MODEL      = 'model-name'\r\n  [ , CREDENTIAL  = &lt;credential_name&gt; ]\r\n  [ , PARAMETERS  = '{\"valid\":\"JSON\"}' ]\r\n  );<\/code><\/pre>\n<p>Supported API_FORMAT values:\u00a0<strong>Azure OpenAI<\/strong>, and\u00a0<strong>OpenAI<\/strong>. The only accepted MODEL_TYPE at GA is EMBEDDINGS. The optional PARAMETERS JSON sets model-level defaults, including retry count:\u00a0<code>'{\"sql_rest_options\":{\"retry_count\":3}}'<\/code>.<\/p>\n<h3>AI_GENERATE_EMBEDDINGS<\/h3>\n<p>AI_GENERATE_EMBEDDINGS is a built-in scalar-valued T-SQL function that references a registered external model, calls its configured embedding endpoint, and returns a JSON array value containing the generated embeddings. It accepts any character expression (nvarchar, varchar, nchar, or char) and can be used in SELECT, INSERT, UPDATE, and MERGE statements, including within procedural code such as stored procedures and triggers.<\/p>\n<p>Syntax:<\/p>\n<pre><code>AI_GENERATE_EMBEDDINGS (\r\n    source\r\n    USE MODEL model_identifier\r\n    [ PARAMETERS optional_json_request_body_parameters ]\r\n)<\/code><\/pre>\n<p>The optional PARAMETERS JSON allows the caller to override model defaults or pass other parameter values to the AI model inference endpoint. For example, the Azure OpenAI REST API supports an optional dimensions parameter that controls the number of dimensions returned \u2014 when supported by the model, PARAMETERS can specify a different value, for example\u00a0<code>'{\"dimensions\":256}'<\/code>.<\/p>\n<h2>GA Capability Summary<\/h2>\n<table>\n<tbody>\n<tr>\n<th>Platform availability<\/th>\n<td>Azure SQL Database, Azure SQL Managed Instance (Always-up-to-date and SQL Server 2025 update policies), SQL Server 2025<\/td>\n<\/tr>\n<tr>\n<th>Embedding providers<\/th>\n<td>Azure OpenAI, OpenAI<\/td>\n<\/tr>\n<tr>\n<th>Authentication<\/th>\n<td>API key via headers (HTTPEndpointHeaders), API key via query string (HTTPEndpointQueryString), Managed Identity, Shared Access Signature Token<\/td>\n<\/tr>\n<tr>\n<th>Model registration<\/th>\n<td>CREATE EXTERNAL MODEL \u2014 registered once, referenced by name in all AI function calls<\/td>\n<\/tr>\n<tr>\n<th>Retry logic<\/th>\n<td>Built-in exponential backoff for transient HTTP errors; configurable via\u00a0<code>sql_rest_options<\/code>\u00a0at model level (PARAMETERS on CREATE EXTERNAL MODEL) or at query level (PARAMETERS on AI_GENERATE_EMBEDDINGS)<\/td>\n<\/tr>\n<tr>\n<th>Permissions<\/th>\n<td>CREATE EXTERNAL MODEL requires CREATE EXTERNAL MODEL or ALTER ANY EXTERNAL MODEL. Calling AI_GENERATE_EMBEDDINGS requires EXECUTE ON EXTERNAL MODEL::ModelName<\/td>\n<\/tr>\n<tr>\n<th>Telemetry<\/th>\n<td>Extended Events:\u00a0<code>ai_generate_embeddings_summary<\/code>\u00a0(status code, errors, model name) and\u00a0<code>external_rest_endpoint_summary<\/code>\u00a0(additional REST detail); performance counters<\/td>\n<\/tr>\n<tr>\n<th>Complimentary features<\/th>\n<td>AI_GENERATE_CHUNKS for text chunking; VECTOR data type for storage; VECTOR_DISTANCE for exact similarity; VECTOR_SEARCH for approximate nearest-neighbor search (preview)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Getting Started<\/h2>\n<p>The following walkthrough sets up native AI embedding generation end-to-end using Azure OpenAI with API key authentication \u2014 the simplest path to get started. Code samples follow the\u00a0<strong>CREATE EXTERNAL MODEL<\/strong>\u00a0and\u00a0<strong>AI_GENERATE_EMBEDDINGS<\/strong>\u00a0reference documentation on Microsoft Learn.<\/p>\n<h3>Step 1: Enable external REST endpoint invocation<\/h3>\n<p>This one-time configuration is required on Azure SQL Managed Instance and SQL Server 2025 before the functions can make outbound REST calls to your embedding endpoint. It is\u00a0<strong>not required on Azure SQL Database<\/strong>.<\/p>\n<pre><code>EXECUTE sp_configure 'external rest endpoint enabled', 1;\r\nRECONFIGURE WITH OVERRIDE;\r\nGO<\/code><\/pre>\n<h3>Step 2: Create a database master key<\/h3>\n<p>A database master key must exist before you can create database-scoped credentials. Skip this step if one already exists.<\/p>\n<pre><code>IF NOT EXISTS (SELECT * FROM sys.symmetric_keys\r\n               WHERE [name] = '##MS_DatabaseMasterKey##')\r\nBEGIN\r\n    CREATE MASTER KEY ENCRYPTION BY PASSWORD = N'&lt;strong-password&gt;';\r\nEND\r\nGO<\/code><\/pre>\n<h3>Step 3: Create a credential for your Azure OpenAI endpoint<\/h3>\n<p>Store your Azure OpenAI API key as a database-scoped credential. The credential name must be the base URL of your Azure OpenAI resource \u2014 in square brackets, with no query string \u2014 because CREATE EXTERNAL MODEL uses this name to match credentials to endpoints. Replace\u00a0<code>&lt;my-azure-openai-endpoint&gt;<\/code>\u00a0with your actual Azure OpenAI resource name.<\/p>\n<pre><code>CREATE DATABASE SCOPED CREDENTIAL [https:\/\/&lt;my-azure-openai-endpoint&gt;.cognitiveservices.azure.com\/]\r\n    WITH IDENTITY = 'HTTPEndpointHeaders',\r\n         SECRET = '{\"api-key\": \"&lt;your-azure-openai-api-key&gt;\"}';\r\nGO<\/code><\/pre>\n<h3>Step 4: Register your embedding model with CREATE EXTERNAL MODEL<\/h3>\n<p>This is the CREATE EXTERNAL MODEL step \u2014 run it once to register your Azure OpenAI embedding deployment as a named object in the database. All subsequent AI_GENERATE_EMBEDDINGS calls reference this name. Replace\u00a0<code>&lt;my-azure-openai-endpoint&gt;<\/code>\u00a0with your resource name and\u00a0<code>text-embedding-ada-002<\/code>\u00a0with your actual deployment name.<\/p>\n<pre><code>CREATE EXTERNAL MODEL MyEmbeddingModel\r\nWITH (\r\n    LOCATION   = 'https:\/\/&lt;my-azure-openai-endpoint&gt;.cognitiveservices.azure.com\/openai\/deployments\/text-embedding-ada-002\/embeddings?api-version=2024-02-01',\r\n    API_FORMAT = 'Azure OpenAI',\r\n    MODEL_TYPE = EMBEDDINGS,\r\n    MODEL      = 'text-embedding-ada-002',\r\n    CREDENTIAL = [https:\/\/&lt;my-azure-openai-endpoint&gt;.cognitiveservices.azure.com\/]\r\n);\r\nGO<\/code><\/pre>\n<h3>Step 5: Grant permission to use the model<\/h3>\n<p>By default, only the model owner can call AI_GENERATE_EMBEDDINGS against it. Grant EXECUTE on the specific model to any other principal that needs to generate embeddings.<\/p>\n<pre><code>-- Permission to create external models (for other users who need to register models)\r\nGRANT CREATE EXTERNAL MODEL TO [&lt;principal&gt;];\r\nGO\r\n\r\n-- Permission to use this specific model in AI_GENERATE_EMBEDDINGS\r\nGRANT EXECUTE ON EXTERNAL MODEL::MyEmbeddingModel TO [&lt;principal&gt;];\r\nGO<\/code><\/pre>\n<h3>Step 6: Create your source and destination tables<\/h3>\n<p>Create a documents table to hold the text you want to embed, and a document_embeddings table with a VECTOR(1536) column to store the generated embeddings. The dimension count (1536) matches text-embedding-ada-002 \u2014 adjust this number if your model outputs a different number of dimensions.<\/p>\n<pre><code>-- Source table\r\nCREATE TABLE documents\r\n(\r\n    id       INT IDENTITY(1,1) PRIMARY KEY,\r\n    content  NVARCHAR(MAX)\r\n);\r\nGO\r\n\r\n-- Destination table for chunk text and embeddings\r\nCREATE TABLE document_embeddings\r\n(\r\n    embeddings_id      INT IDENTITY(1,1) PRIMARY KEY,\r\n    chunk_text         NVARCHAR(100),\r\n    vector_embeddings  VECTOR(1536)\r\n);\r\nGO<\/code><\/pre>\n<h3>Step 7: Insert your source text<\/h3>\n<p>Insert the text you want to embed into the documents table. Replace these sample rows with your own data.<\/p>\n<pre><code>INSERT INTO documents (content)\r\nVALUES\r\n    ('Your first document or text passage goes here.'),\r\n    ('Your second document or text passage goes here.');\r\nGO<\/code><\/pre>\n<h3>Step 8: Generate and store embeddings with AI_GENERATE_EMBEDDINGS<\/h3>\n<p>Use <a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/t-sql\/functions\/ai-generate-chunks-transact-sql?view=sql-server-ver17\">AI_GENERATE_CHUNKS<\/a> to split the content column into fixed-size chunks, then call AI_GENERATE_EMBEDDINGS referencing the model registered in Step 4. The chunk text and its vector array are inserted directly into document_embeddings.<\/p>\n<pre><code>INSERT INTO document_embeddings (chunk_text, vector_embeddings)\r\nSELECT c.chunk,\r\n       AI_GENERATE_EMBEDDINGS(c.chunk USE MODEL MyEmbeddingModel)\r\nFROM documents AS t\r\nCROSS APPLY AI_GENERATE_CHUNKS(\r\n    SOURCE     = t.content,\r\n    CHUNK_TYPE = FIXED,\r\n    CHUNK_SIZE = 100\r\n) AS c;\r\nGO<\/code><\/pre>\n<p>Verify the results:<\/p>\n<pre><code>SELECT * FROM document_embeddings;<\/code><\/pre>\n<blockquote><p><strong>Tip: Configuring retry count<\/strong><\/p>\n<p>If an embeddings call encounters transient HTTP errors (such as 429 Too Many Requests), the function retries automatically. Retry count can be set at the model level (applies to all calls) or overridden at query time. The value must be a whole number between 0 and 10.<\/p>\n<p>Model level \u2014 in CREATE EXTERNAL MODEL PARAMETERS:\u00a0<code>'{\"sql_rest_options\":{\"retry_count\":3}}'<\/code><\/p>\n<p>Query level \u2014 in AI_GENERATE_EMBEDDINGS PARAMETERS:\u00a0<code>'{\"sql_rest_options\":{\"retry_count\":10}}'<\/code><\/p><\/blockquote>\n<pre><code>-- Query-level retry override example\r\nDECLARE @params JSON = N'{\"sql_rest_options\":{\"retry_count\":10}}'\r\n\r\nSELECT id,\r\n       AI_GENERATE_EMBEDDINGS(content USE MODEL MyEmbeddingModel PARAMETERS @params)\r\nFROM   documents;<\/code><\/pre>\n<h2>Summary<\/h2>\n<p><strong>AI_GENERATE_EMBEDDINGS<\/strong>\u00a0and\u00a0<strong>CREATE EXTERNAL MODEL<\/strong>\u00a0are now generally available in Azure SQL Database and Azure SQL Managed Instance.\u00a0<strong>CREATE EXTERNAL MODEL<\/strong>\u00a0registers your AI endpoint as a named database object;\u00a0<strong>AI_GENERATE_EMBEDDINGS<\/strong>\u00a0securely calls that endpoint to generate vector embeddings directly from T-SQL. At GA, the pipeline includes built-in retry logic for transient errors. Vectors are stored in VECTOR-typed columns and queried using SQL&#8217;s native vector search capabilities \u2014 no external pipeline, no data movement required. Try it today and let us know what you build.<\/p>\n<p>Full reference documentation on Microsoft Learn:\u00a0<a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/t-sql\/statements\/create-external-model-transact-sql?view=sql-server-ver17\">CREATE EXTERNAL MODEL<\/a>\u00a0\u00b7\u00a0<a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/t-sql\/functions\/ai-generate-embeddings-transact-sql?view=sql-server-ver17\">AI_GENERATE_EMBEDDINGS<\/a><\/p>\n<p><em>Tags: azure sql database \u00b7 azure sql managed instance \u00b7 sql server 2025 \u00b7 create external model \u00b7 ai \u00b7 embeddings \u00b7 vector search \u00b7 rag \u00b7 t-sql<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We are excited to announce the General Availability (GA) of\u00a0AI_GENERATE_EMBEDDINGS\u00a0and\u00a0CREATE EXTERNAL MODEL\u00a0in\u00a0Azure SQL Database\u00a0and\u00a0Azure SQL Managed Instance. These two T-SQL features \u2014\u00a0CREATE EXTERNAL MODEL\u00a0and\u00a0AI_GENERATE_EMBEDDINGS\u00a0\u2014 work together as a single, integrated pipeline for generating vector embeddings directly from T-SQL. No data movement, no external orchestration, no application-layer pipeline required. EXTERNAL MODEL object\u00a0defines\u00a0where\u00a0to get embeddings from and [&hellip;]<\/p>\n","protected":false},"author":193439,"featured_media":81,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7081","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure-sql"],"acf":[],"blog_post_summary":"<p>We are excited to announce the General Availability (GA) of\u00a0AI_GENERATE_EMBEDDINGS\u00a0and\u00a0CREATE EXTERNAL MODEL\u00a0in\u00a0Azure SQL Database\u00a0and\u00a0Azure SQL Managed Instance. These two T-SQL features \u2014\u00a0CREATE EXTERNAL MODEL\u00a0and\u00a0AI_GENERATE_EMBEDDINGS\u00a0\u2014 work together as a single, integrated pipeline for generating vector embeddings directly from T-SQL. No data movement, no external orchestration, no application-layer pipeline required. EXTERNAL MODEL object\u00a0defines\u00a0where\u00a0to get embeddings from and [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts\/7081","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/users\/193439"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/comments?post=7081"}],"version-history":[{"count":2,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts\/7081\/revisions"}],"predecessor-version":[{"id":7085,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts\/7081\/revisions\/7085"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/media\/81"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/media?parent=7081"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/categories?post=7081"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/tags?post=7081"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}