{"id":4744,"date":"2025-05-28T16:46:58","date_gmt":"2025-05-28T23:46:58","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/azure-sql\/?p=4744"},"modified":"2025-06-12T08:19:15","modified_gmt":"2025-06-12T15:19:15","slug":"getting-started-with-ai-in-sql-server-2025-on-windows","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/azure-sql\/getting-started-with-ai-in-sql-server-2025-on-windows\/","title":{"rendered":"Getting started with AI in SQL Server 2025 on Windows"},"content":{"rendered":"<p>Back in the earlier part of the year (February maybe?), I put this tutorial together for our early adopters in the SQL Server 2025 program. It\u2019s a guide for setting up SQL Server 2025 in a Hyper-V VM (I used Windows Server) with Ollama and ngnix as an https proxy. It&#8217;s a variation of my <a href=\"https:\/\/github.com\/Azure-Samples\/sql-ai-embeddings-workshop\">workshops for Ignite 2024<\/a> and a <a href=\"https:\/\/github.com\/Azure-Samples\/sql-in-fabric-ai-embeddings-workshop\">SQL in Fabric<\/a> one from February 2025.<\/p>\n<p>This tutorial helps you get started using the new AI features of SQL Server 2025 on Windows\/Windows Server.<\/p>\n<h2>Prerequisites<\/h2>\n<ul>\n<li><a href=\"https:\/\/aka.ms\/sql2025\">SQL Server 2025 Public Preview<\/a><\/li>\n<li>A database created with the adventureworks2025.bak backup file<\/li>\n<li><a href=\"https:\/\/learn.microsoft.com\/en-us\/ssms\/install\/install\">SSMS<\/a> or VS Code with the MSSQL Extension<\/li>\n<li>Windows environment or Hyper-V Windows VM (Windows or <a href=\"https:\/\/www.microsoft.com\/evalcenter\/download-windows-server-2025\">Windows Server<\/a>)<\/li>\n<\/ul>\n<h2>Set up your environment<\/h2>\n<p>The following section guides you through setting up the environment and installing the necessary software and utilities.<\/p>\n<h3>Install Ollama<\/h3>\n<p>There are two ways to install Ollama.<\/p>\n<p><strong>Via Winget and PowerShell<\/strong><\/p>\n<p>1. Open up a PowerShell terminal<\/p>\n<p>2. Enter the following command:<\/p>\n<pre>winget install Ollama.Ollama<\/pre>\n<p><strong>Via Direct Download<\/strong><\/p>\n<p>1. Download the executable file from the GitHub repository using the following link: <a href=\"https:\/\/github.com\/ollama\/ollama\/releases\">Ollama Setup<\/a><\/p>\n<p>2. Then double-click the `OllamaSetup.exe` file to install Ollama.<\/p>\n<p>3. Once Ollama is installed, quit or stop it from either the task manager or in the system tray, right select Ollama and select **Quit Ollama**.<\/p>\n<h3>Install nginx<\/h3>\n<p>1. To install <strong>nginx<\/strong>, use the following link to download it: <a href=\"https:\/\/nginx.org\/en\/download.html\">Download Nginx<\/a><\/p>\n<p>2. Under the heading **Stable version**, select `nginx\/Windows-1.28.0` (the version on as of May 19, 2025) to start the download.<\/p>\n<p>3. Copy the `nginx-1.28.0.zip` file to the `C:\\` drive<\/p>\n<p>4. Unzip the `nginx-1.28.0.zip` file here. In Windows, use the **Extract All&#8230;** option when right selecting on the file.<\/p>\n<p>5. In the Extract Compressed File dialog, set the extraction directory to be `C:\\`. If you leave the default, it will extract the files into a nested folder resulting in `C:\\nginx-1.28.0\\nginx-1.28.0`.<\/p>\n<h3>Set up SSL for Ollama and nginx<\/h3>\n<p>The next step will create self-signed certificates that will be used for SSL in nginx.<\/p>\n<p>1. To start, open a PowerShell terminal and create a certs directory with the following command:<\/p>\n<pre>mkdir C:\\certs<\/pre>\n<p>2. Next, using Notepad, copy the following text and save the file as createCert.ps1 in the C:\\certs directory.<\/p>\n<p>createCert.ps1<\/p>\n<pre>param\r\n(\r\n[parameter(Mandatory=$true)]\r\n[string]\r\n$DnsName,\r\n\r\n[parameter(Mandatory=$true)]\r\n[string]\r\n$Password,\r\n\r\n[parameter(Mandatory=$true)]\r\n[string]\r\n$FilePath\r\n)\r\n\r\n# Create a new self-signed certificate\r\n$cert = New-SelfSignedCertificate -Subject $DnsName -DnsName $DnsName -FriendlyName \"SQL Development\"\r\n\r\n# Export the certificate to a file\r\nExport-PfxCertificate -Cert $cert -FilePath $FilePath -Password (ConvertTo-SecureString -String $Password -Force -AsPlainText)\r\n\r\n# Import the certificate as trusted\r\nImport-PfxCertificate -Certstorelocation Cert:\\LocalMachine\\Root -FilePath $FilePath -Password (ConvertTo-SecureString -String $Password -Force -AsPlainText)\r\n\r\n<\/pre>\n<p>2. Close Notepad after saving the file and go back to the PowerShell terminal.<\/p>\n<p>3. Change the directory to the C:\\certs directory<\/p>\n<pre>cd C:\\certs<\/pre>\n<p>4. Next, run the createCert.ps1 script with the following command:<\/p>\n<pre>.\/createCert.ps1<\/pre>\n<p>5. Use the following values for the variables when running the createCert.ps1 script:<\/p>\n<ul>\n<li>For DnsName, use `localhost`\nFor password, use a strong password that you have written down.\nFor FilePath, use `C:\\certs\\cert.pfx`<\/li>\n<\/ul>\n<p>The certificate is now created.<\/p>\n<h3>Install OpenSSL<\/h3>\n<p>OpenSSL needs to be installed next.<\/p>\n<p>1. While in the PowerShell terminal, run the following command:<\/p>\n<pre>winget install ShiningLight.OpenSSL.Light<\/pre>\n<h3>Add OpenSSL to the PATH<\/h3>\n<p>Once installed, openssl needs to be added to the PATH environment variable.<\/p>\n<p><strong>Via PowerShell<\/strong><\/p>\n<p>Run the following command in the PowerShell terminal:<\/p>\n<pre>$oldPath = [Environment]::GetEnvironmentVariable(\"Path\", \"User\")\r\n$newPath = $oldPath + \";C:\\Program Files\\OpenSSL-Win64\\bin\"\r\n[Environment]::SetEnvironmentVariable(\"Path\", $newPath, \"User\")<\/pre>\n<p><strong>Via the Environment Variables modal window<\/strong><\/p>\n<p>1. Start by running the following command in the PowerShell terminal:<\/p>\n<pre>rundll32 sysdm.cpl,EditEnvironmentVariables<\/pre>\n<p>2. In the<strong> Environment Variables<\/strong> modal window, look at the lower section named <strong>System variables<\/strong>.<\/p>\n<p>3. Select the <strong>Path<\/strong>\u00a0variable and then select the <strong>Edit<\/strong>\u00a0button.<\/p>\n<p>4. In the <strong>Edit environment variable<\/strong> modal window, start by selecting the <strong>New<\/strong>\u00a0button.<\/p>\n<p>5. Under the last line, you can enter text for the next variable. Use the following text:<\/p>\n<pre>C:\\Program Files\\OpenSSL-Win64\\bin<\/pre>\n<p>6. Then press the <strong>OK<\/strong> button to set the variable and close the modal window. Then, select <strong>OK<\/strong> to close the <strong>Environment Variables<\/strong>\u00a0modal window.<\/p>\n<h3>Create the signed .crt and .key files for nginx<\/h3>\n<p>1. To use the new Path, run the following command in the PowerShell terminal:<\/p>\n<pre>$env:Path = [System.Environment]::GetEnvironmentVariable(\"Path\",\"Machine\") + \";\" + [System.Environment]::GetEnvironmentVariable(\"Path\",\"User\")<\/pre>\n<p>2. Ensure the directory is still set to C:\\certs. Run the following command if unsure:<\/p>\n<pre>cd C:\\certs<\/pre>\n<p>3. Next, run the following command:<\/p>\n<pre>openssl pkcs12 -in cert.pfx -nocerts -out cert.key -nodes<\/pre>\n<p>4. When asked to <strong>&#8220;Enter Import Password&#8221;<\/strong>, enter the strong password you wrote down previously. Then press the enter\/return key.<\/p>\n<p>5. Now, run the following command:<\/p>\n<pre>openssl pkcs12 -in cert.pfx -clcerts -nokeys -out cert.crt<\/pre>\n<p>6. When asked to <strong>&#8220;Enter Import Password&#8221;<\/strong>, enter the strong password you wrote down previously. Then press the enter\/return key.<\/p>\n<h3>Edit the nginx.conf file<\/h3>\n<p>1. Again in the PowerShell terminal, run the following command:<\/p>\n<p><strong>NOTE: The version number installed might be different than the one in this tutorial.<\/strong><\/p>\n<pre>cd C:\\nginx-1.28.0\\conf<\/pre>\n<p>2. Now, edit this file by opening it in Notepad using the following command in PowerShell:<\/p>\n<pre>notepad nginx.conf<\/pre>\n<p>3. Replace <strong>ALL<\/strong>\u00a0the text in the nginx.conf with the following:<\/p>\n<pre>worker_processes auto;\r\n\r\nevents {\r\nworker_connections 1024;\r\n}\r\n\r\nhttp {\r\n\r\nupstream ollama {\r\nserver localhost:11434;\r\n}\r\n\r\nserver {\r\nlisten 11435 ssl;\r\nserver_name localhost;\r\n\r\nssl_certificate C:\\certs\\cert.crt;\r\nssl_certificate_key C:\\certs\\cert.key;\r\nssl_protocols TLSv1 TLSv1.1 TLSv1.2;\r\nssl_ciphers HIGH:!aNULL:!MD5;\r\n\r\nlocation \/ {\r\nproxy_pass http:\/\/localhost:11434;\r\nproxy_http_version 1.1;\r\nproxy_set_header Host $host;\r\nproxy_set_header X-Real-IP $remote_addr;\r\nproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\r\nproxy_set_header X-Forwarded-Proto $scheme;\r\nproxy_set_header Origin '';\r\nproxy_set_header Referer '';\r\n}\r\n}\r\n}<\/pre>\n<p>4. <strong>Save the file<\/strong><\/p>\n<p>5. After you have **<strong>Saved the nginx.conf file<\/strong>**, change the directory in PowerShell using the following command:<\/p>\n<pre>cd C:\\Windows\\System32\\drivers\\etc<\/pre>\n<p>6. Edit the hosts file with Notepad using the following command:<\/p>\n<pre>notepad hosts<\/pre>\n<p>7. After the last line in the file, add the following text:<\/p>\n<pre>127.0.0.1 localhost<\/pre>\n<p>8. <strong>Save the file<\/strong><\/p>\n<p>9. After you have **<strong>Saved the hosts file<\/strong>**, it&#8217;s time to start up the services.<\/p>\n<h2>Start up the services<\/h2>\n<h3>Ollama<\/h3>\n<p>1. Start by going to the top level of the C: Drive with the following command in PowerShell:<\/p>\n<pre>Set-Location -Path \"C:\\\"<\/pre>\n<p>2. Back in PowerShell, Ollama needs an embedding model locally. Use the following command to download that model:<\/p>\n<pre>ollama pull nomic-embed-text<\/pre>\n<p>3. Pulling the model also start Ollama up. We want to stop it so we can start it in PowerShell to monitor the requests. Again stop Ollama from either the task manager or in the system tray, right-click Ollama and select **<strong>Quit Ollama<\/strong>**.<\/p>\n<p>4. Once Ollama as stopped, start Ollama with the following command so that we can monitor it in PowerShell:<\/p>\n<pre>ollama serve<\/pre>\n<h3>Nginx<\/h3>\n<p>1. Open a new PowerShell terminal by <strong>clicking the Plus Sign<\/strong>\u00a0on the PowerShell terminal tab area.<\/p>\n<p>2. Change the directory to the nginx home directory using the following command in PowerShell:<\/p>\n<p><strong>NOTE: The version number installed might be different than the one in this tutorial.<\/strong><\/p>\n<pre>cd C:\\nginx-1.28.0<\/pre>\n<p>3. To start nginx, run the following command in PowerShell:<\/p>\n<pre>start nginx<\/pre>\n<h2>Test the Ollama embeddings endpoint<\/h2>\n<p>To test the endpoint, run the following command in PowerShell:<\/p>\n<pre>Invoke-WebRequest -Uri \"https:\/\/localhost:11435\/api\/embed\" -ContentType \"application\/json\" -Method POST -Body '{ \"model\":\"nomic-embed-text\", \"prompt\":\"test text\"}'<\/pre>\n<p>And the result should be similar to the following:<\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace\">StatusCode : 200<\/span>\n<span style=\"font-family: 'courier new', courier, monospace\">StatusDescription : OK<\/span>\n<span style=\"font-family: 'courier new', courier, monospace\">Content : {&#8220;model&#8221;:&#8221;nomic-embed-text&#8221;,&#8221;embeddings&#8221;:[0.021354584,-0.026753489,-0.16089542,-0.026369257,0.0828<\/span>\n<span style=\"font-family: 'courier new', courier, monospace\">7482,-0.03691292,0.022429287,-0.008543771,0.012165211,-0.02446957,-0.01350472,0.072527215,0.0365559<\/span>\n<span style=\"font-family: 'courier new', courier, monospace\">64&#8230;<\/span>\n<span style=\"font-family: 'courier new', courier, monospace\">RawContent : HTTP\/1.1 200 OK<\/span>\n<span style=\"font-family: 'courier new', courier, monospace\">Transfer-Encoding: chunked<\/span>\n<span style=\"font-family: 'courier new', courier, monospace\">Connection: keep-alive<\/span>\n<span style=\"font-family: 'courier new', courier, monospace\">Content-Type: application\/json; charset=utf-8<\/span>\n<span style=\"font-family: 'courier new', courier, monospace\">Date: Fri, 07 Mar 2025 17:12:36 GMT<\/span>\n<span style=\"font-family: 'courier new', courier, monospace\">Server: nginx\/1.28.0<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace\">{&#8220;model&#8221;:&#8221;nomic-embed-t&#8230;<\/span>\n<span style=\"font-family: 'courier new', courier, monospace\">Forms : {}<\/span>\n<span style=\"font-family: 'courier new', courier, monospace\">Headers : {[Transfer-Encoding, chunked], [Connection, keep-alive], [Content-Type, application\/json;<\/span>\n<span style=\"font-family: 'courier new', courier, monospace\">charset=utf-8], [Date, Fri, 07 Mar 2025 17:12:36 GMT]&#8230;}<\/span>\n<span style=\"font-family: 'courier new', courier, monospace\">Images : {}<\/span>\n<span style=\"font-family: 'courier new', courier, monospace\">InputFields : {}<\/span>\n<span style=\"font-family: 'courier new', courier, monospace\">Links : {}<\/span>\n<span style=\"font-family: 'courier new', courier, monospace\">ParsedHtml : System.__ComObject<\/span>\n<span style=\"font-family: 'courier new', courier, monospace\">RawContentLength : 9634<\/span><\/p>\n<p>If you look at the Ollama PowerShell tab, you see a line similar to the following:<\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace\">[GIN] 2025\/03\/07 &#8211; 09:12:36 | 200 | 27.8195ms | 127.0.0.1 | POST &#8220;\/api\/embed&#8221;<\/span><\/p>\n<h2>Set up the database<\/h2>\n<p>The following section guides you through using the embeddings model to create vector arrays on relation data and use the new vector similarity search functionality in SQL Server 2025.<\/p>\n<h3>Create the EXTERNAL MODEL in the database<\/h3>\n<p>1. Using SSMS, login to the database using Windows credentials<\/p>\n<p>2. Open a new query sheet using the <strong>AdventureWorksLT2025 database<\/strong><\/p>\n<p>3. Next, run the following SQL to enable REST communication from within the database:<\/p>\n<pre>-- Turn External REST Endpoint Invocation ON in the database\r\nEXECUTE sp_configure 'external rest endpoint enabled', 1;\r\nGO\r\n\r\nRECONFIGURE WITH OVERRIDE;\r\nGO<\/pre>\n<p>Now, run the following SQL to create an EXTERNAL MODEL that points to the Ollama embedding model that was downloaded:<\/p>\n<pre>CREATE EXTERNAL MODEL ollama\r\nWITH (\r\nLOCATION = 'https:\/\/localhost:11435\/api\/embed',\r\nAPI_FORMAT = 'Ollama',\r\nMODEL_TYPE = EMBEDDINGS,\r\nMODEL = 'nomic-embed-text'\r\n);<\/pre>\n<h3>Test the EXTERNAL MODEL<\/h3>\n<p>To test the embeddings endpoint, run the following SQL:<\/p>\n<pre>select AI_GENERATE_EMBEDDINGS(N'test text' USE MODEL ollama);<\/pre>\n<p>You should see a JSON vector array returned similar to the following:<\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace\">[0.1529204398393631,0.4368368685245514,-3.6136839389801025,-0.7697131633758545&#8230;<\/span><\/p>\n<p>Watch Ollama in the PowerShell terminal where you started it to see any errors or successes.<\/p>\n<h3>Embed Product Data<\/h3>\n<p>This next section of the tutorial will alter the Adventure Works product table to add a new vector data type column.<\/p>\n<p>1. Run the following SQL to add the columns to the Product table:<\/p>\n<pre>ALTER TABLE [SalesLT].[Product]\r\nADD embeddings VECTOR (768),\r\nchunk NVARCHAR (2000);<\/pre>\n<p>2. Next, we are going to use the EXTERNAL MODEL and AI_GENERATE_EMBEDDINGS to create embeddings for text we supply as an input.<\/p>\n<p>Run the following code to create the embeddings:<\/p>\n<pre>-- create the embeddings\r\nSET NOCOUNT ON;\r\n\r\nDROP TABLE IF EXISTS #MYTEMP;\r\n\r\nDECLARE @ProductID int\r\nDECLARE @text NVARCHAR (MAX);\r\n\r\nSELECT * INTO #MYTEMP FROM [SalesLT].Product WHERE embeddings IS NULL;\r\n\r\nSELECT @ProductID = ProductID FROM #MYTEMP;\r\n\r\nSELECT TOP(1) @ProductID = ProductID FROM #MYTEMP;\r\n\r\nWHILE @@ROWCOUNT &lt;&gt; 0\r\nBEGIN\r\nSET @text = (\r\nSELECT p.Name + ' ' + ISNULL(p.Color, 'No Color') + ' ' + c.Name + ' ' + m.Name + ' ' + ISNULL(d.Description, '')\r\nFROM [SalesLT].[ProductCategory] c,\r\n[SalesLT].[ProductModel] m,\r\n[SalesLT].[Product] p\r\nLEFT OUTER JOIN [SalesLT].[vProductAndDescription] d\r\nON p.ProductID = d.ProductID\r\nAND d.Culture = 'en'\r\nWHERE p.ProductCategoryID = c.ProductCategoryID\r\nAND p.ProductModelID = m.ProductModelID\r\nAND p.ProductID = @ProductID\r\n);\r\nUPDATE [SalesLT].[Product] SET [embeddings] = AI_GENERATE_EMBEDDINGS(@text USE MODEL ollama), [chunk] = @text WHERE ProductID = @ProductID;\r\n\r\nDELETE FROM #MYTEMP WHERE ProductID = @ProductID;\r\n\r\nSELECT TOP(1) @ProductID = ProductID FROM #MYTEMP;\r\nEND<\/pre>\n<p>2. Use the following query to see if any embeddings were missed:<\/p>\n<pre>SELECT *\r\nFROM SalesLT.Product\r\nWHERE embeddings IS NULL;<\/pre>\n<p>3. And use this query to see a sample of the new columns and the data within:<\/p>\n<pre>SELECT TOP 10 chunk,\r\nembeddings\r\nFROM SalesLT.Product;<\/pre>\n<h2>Use VECTOR_DISTANCE and VECTOR_SEARCH<\/h2>\n<p>Vector similarity searching is a technique used to find and retrieve data points that are similar to a given query, based on their vector representations. The similarity between two vectors is measured using a distance metric, such as cosine similarity or Euclidean distance. These metrics quantify the similarity between two vectors by calculating the angle between them or the distance between their coordinates in the vector space.<\/p>\n<p>Vector similarity searching has numerous applications, such as recommendation systems, search engines, image and video retrieval, and natural language processing tasks. It allows for efficient and accurate retrieval of similar items, enabling users to find relevant information or discover related items quickly and effectively.<\/p>\n<p>This section of the tutorial will be using the new functions VECTOR_DISTANCE and VECTOR_SEARCH. It will also be creating a new DiskANN Vector Index for the VECTOR_SEARCH ANN similarity searches.<\/p>\n<h3>VECTOR_DISTANCE<\/h3>\n<p>Uses K-Nearest Neighbors or KNN<\/p>\n<p>Use the following SQL to run similarity searches using VECTOR_DISTANCE.<\/p>\n<pre>declare @search_text nvarchar(max) = 'I am looking for a red bike and I dont want to spend a lot'\r\ndeclare @search_vector vector(768) = AI_GENERATE_EMBEDDINGS(@search_text USE MODEL ollama);\r\nSELECT TOP(4)\r\np.ProductID, p.Name , p.chunk,\r\nvector_distance('cosine', @search_vector, p.embeddings) AS distance\r\nFROM [SalesLT].[Product] p\r\nORDER BY distance;\r\n\r\ndeclare @search_text nvarchar(max) = 'I am looking for a safe helmet that does not weigh much'\r\ndeclare @search_vector vector(768) = AI_GENERATE_EMBEDDINGS(@search_text USE MODEL ollama);\r\nSELECT TOP(4)\r\np.ProductID, p.Name , p.chunk,\r\nvector_distance('cosine', @search_vector, p.embeddings) AS distance\r\nFROM [SalesLT].[Product] p\r\nORDER BY distance;\r\n\r\ndeclare @search_text nvarchar(max) = 'Do you sell any padded seats that are good on trails?'\r\ndeclare @search_vector vector(768) = AI_GENERATE_EMBEDDINGS(@search_text USE MODEL ollama);\r\nSELECT TOP(4)\r\np.ProductID, p.Name , p.chunk,\r\nvector_distance('cosine', @search_vector, p.embeddings) AS distance\r\nFROM [SalesLT].[Product] p\r\nORDER BY distance;<\/pre>\n<h3>VECTOR_SEARCH<\/h3>\n<p>Uses Approximate Nearest Neighbors or ANN<\/p>\n<p>Use the following SQL to run similarity searches using VECTOR_SEARCH and the DiskANN Vector Index.<\/p>\n<p>1. First, run the following SQL to prepare the database to use the new features:<\/p>\n<pre>-- Enable trace flags for vector features\r\nDBCC TRACEON (466, 474, 13981, -1);\r\nGO\r\n\r\n-- Check trace flags status\r\nDBCC TRACESTATUS;\r\nGO<\/pre>\n<p>2. Now, create the DiskANN indexes on the embeddings column in the Product table.<\/p>\n<pre>CREATE VECTOR INDEX vec_idx ON [SalesLT].[Product]([embeddings])\r\nWITH (METRIC = 'cosine', TYPE = 'diskann', MAXDOP = 8);\r\nGO\r\n\r\nSELECT * FROM sys.indexes WHERE type = 8;\r\nGO<\/pre>\n<p>3. Use the following SQL to run the similarity search using both VECTOR_SEARCH and the DiskANN Index:<\/p>\n<pre>-- ANN Search\r\nDECLARE @search_text NVARCHAR (MAX) = 'Do you sell any padded seats that are good on trails?';\r\nDECLARE @search_vector VECTOR (768) = AI_GENERATE_EMBEDDINGS(@search_text USE MODEL ollama);\r\nSELECT t.chunk,\r\ns.distance\r\nFROM vector_search(\r\ntable = [SalesLT].[Product] as t,\r\ncolumn = [embeddings],\r\nsimilar_to = @search_vector,\r\nmetric = 'cosine',\r\ntop_n = 10\r\n) as s\r\nORDER BY s.distance;\r\nGO<\/pre>\n<h3>Chunk with embeddings<\/h3>\n<p>This section uses the `AI_GENERATE_CHUNKS` function with `AI_GENERATE_EMBEDDINGS` to simulate breaking a large section of text into smaller set sized chunks to be embedded.<\/p>\n<p>1. First, create a table to hold the text:<\/p>\n<pre>CREATE TABLE textchunk\r\n(\r\ntext_id INT IDENTITY (1, 1) PRIMARY KEY,\r\ntext_to_chunk NVARCHAR (MAX)\r\n);\r\nGO<\/pre>\n<p>2. Next, insert the text into the table:<\/p>\n<pre>INSERT INTO textchunk (text_to_chunk)\r\nVALUES ('All day long we seemed to dawdle through a country which was full of beauty of every kind. Sometimes we saw little towns or castles on the top of steep hills such as we see in old missals; sometimes we ran by rivers and streams which seemed from the wide stony margin on each side of them to be subject to great floods.'),\r\n('My Friend, Welcome to the Carpathians. I am anxiously expecting you. Sleep well to-night. At three to-morrow the diligence will start for Bukovina; a place on it is kept for you. At the Borgo Pass my carriage will await you and will bring you to me. I trust that your journey from London has been a happy one, and that you will enjoy your stay in my beautiful land. Your friend, DRACULA');\r\nGO<\/pre>\n<p>3. Finally, create chunks of text to be embedded using both functions:<\/p>\n<pre>SELECT c.*, AI_GENERATE_EMBEDDINGS(c.chunk USE MODEL ollama)\r\nFROM textchunk t\r\nCROSS APPLY\r\nAI_GENERATE_CHUNKS(source = text_to_chunk, chunk_type = N'FIXED', chunk_size = 50, overlap = 10) c<\/pre>\n<h2>XEvents for embeddings and REST<\/h2>\n<p>The following SQL creates an XEvent session for debugging REST calls from the database<\/p>\n<pre>CREATE EVENT SESSION [rest] ON SERVER\r\nADD EVENT sqlserver.external_rest_endpoint_summary,\r\nADD EVENT sqlserver.ai_generate_embeddings_summary\r\nWITH\r\n(\r\nMAX_MEMORY = 4096 KB,\r\nEVENT_RETENTION_MODE = ALLOW_SINGLE_EVENT_LOSS,\r\nMAX_DISPATCH_LATENCY = 30 SECONDS,\r\nMAX_EVENT_SIZE = 0 KB,\r\nMEMORY_PARTITION_MODE = NONE,\r\nTRACK_CAUSALITY = OFF,\r\nSTARTUP_STATE = OFF\r\n);\r\nGO\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Back in the earlier part of the year (February maybe?), I put this tutorial together for our early adopters in the SQL Server 2025 program. It\u2019s a guide for setting up SQL Server 2025 in a Hyper-V VM (I used Windows Server) with Ollama and ngnix as an https proxy. It&#8217;s a variation of my [&hellip;]<\/p>\n","protected":false},"author":95874,"featured_media":4759,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[601,599,582,576,577,672,619],"tags":[590,602,510,588,465,469,30,449,561,627,410,34,569,591],"class_list":["post-4744","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai","category-azure-openai","category-openai","category-rest","category-rest-endpoint-invocation","category-sql-server-2025","category-t-sql","tag-ai","tag-azure-openai","tag-azure-sql-database","tag-azure-sql-db","tag-azuresql","tag-azuresqldb","tag-developers","tag-development","tag-openai","tag-rag","tag-rest","tag-t-sql","tag-vector","tag-vector-search"],"acf":[],"blog_post_summary":"<p>Back in the earlier part of the year (February maybe?), I put this tutorial together for our early adopters in the SQL Server 2025 program. It\u2019s a guide for setting up SQL Server 2025 in a Hyper-V VM (I used Windows Server) with Ollama and ngnix as an https proxy. It&#8217;s a variation of my [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts\/4744","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\/95874"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/comments?post=4744"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts\/4744\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/media\/4759"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/media?parent=4744"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/categories?post=4744"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/tags?post=4744"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}