Press "Enter" to skip to content

Posts published in “AI”

How to call Ollama AI models from SQL Server 2025 in parallel with hint

Michal 0

If you have already installed Ollama server, for example based on this article Setting Up Ollama for SQL Server 2025: A Guide - John Deardurff, then you need to register the model on SQL Server.

Example:

CREATE EXTERNAL MODEL OllamaAI
WITH (
LOCATION = 'https://localollama/v1/embeddings',
API_FORMAT = 'OpenAI',
MODEL_TYPE = EMBEDDINGS,
MODEL = 'bge-m3'
);

Now you can start generating vector embeddings directly from SQL Server.
This allows you to convert text into vector form and later perform vector similarity comparisons.
The following example inserts embeddings for all missing rows from an existing table, using parallel execution via a query hint:

Create table dbo.SampleTable
(ProductDescriptionId int, Embedding vector(768))

Insert into dbo.SampleTable
(ProductDescriptionId, Embedding)
SELECT ProductDescriptionID,
AI_GENERATE_EMBEDDINGS(Description USE MODEL OllamaAI_2)
FROM [Production].[ProductDescription] A
WHERE
NOT EXISTS(SELECT 1 FROM dbo.SampleTable B WHERE
B.ProductDescriptionId=A.ProductDescriptionID)
OPTION (USE HINT('ENABLE_PARALLEL_PLAN_PREFERENCE'))