Vector search and embeddings in SQL, explained

What embeddings and vector search are, the vector type and VECTOR_DISTANCE in SQL Server 2025, Azure SQL and Fabric, and when exact search is enough.

Short answer: an embedding is a list of numbers a model makes from a text (or an image) so that similar meanings get similar numbers. Vector search finds the rows whose embeddings are closest to a question's embedding. SQL Server 2025, Azure SQL Database, Azure SQL Managed Instance and SQL database in Fabric have a vector type and VECTOR_DISTANCE, so this runs in the database, next to the rows it describes.

Keyword search finds "bike" only where the word is. Vector search also finds "bicycle" and "e-bike", because their embeddings sit close together.

How does a search run?

  1. 1
    Question"waterproof jacket for cycling"
  2. 2
    Embeddingthe same model turns it into a vector
  3. 3
    Distanceto every product's stored vector
  4. 4
    Closest rowsthe products nearest in meaning
From a question to the closest rows

The products' embeddings are made once and stored in a column; only the question is embedded at search time. Both must come from the same model.

What does it look like in T-SQL?

ALTER TABLE dbo.Product ADD DescriptionVector vector(1536);

DECLARE @q vector(1536) = AI_GENERATE_EMBEDDINGS(N'waterproof jacket for cycling' USE MODEL MyEmbeddingModel);

SELECT TOP (10) ProductID, Name,
       VECTOR_DISTANCE('cosine', @q, DescriptionVector) AS Distance
FROM dbo.Product
ORDER BY Distance;

AI_GENERATE_EMBEDDINGS calls a model you registered in the database with CREATE EXTERNAL MODEL; you can also make the embeddings outside and store them. Vectors are stored compactly and shown as JSON arrays, so CAST('[0.1, -0.2, 0.3]' AS vector(3)) works too.

Exact search or a vector index?

WayHowWhen
Exact (kNN)VECTOR_DISTANCE on every candidate rowup to about 50,000 vectors after other filters
Approximate (ANN)a vector index (DiskANN) and VECTOR_SEARCHfar more vectors, when nearly exact is fine
Two ways to find the nearest vectors

Start exact: it is always right, and a WHERE on category or date often brings the candidates under the limit. Add a vector index when the table outgrows it. The vector type and functions are generally available in all four products; vector indexes are generally available in Azure SQL Database and SQL database in Fabric, and in preview in SQL Server 2025.

What goes wrong?

  • Two models. Embeddings from different models cannot be compared. Store the model's name with the vectors, and re-embed when you change it.
  • Stale embeddings. When a description changes, its vector must too. Re-embed in the same step that updates the row, or from change tracking.
  • Whole documents in one vector. A long text squeezed into one embedding blurs. Split it into chunks and embed each.

Where can you check this?

Where do you start?

DP-800 in 2026 shows how vector search leads to answering questions from your own rows, and the open course Upserts into Azure SQL builds the kind of table you would add a vector column to.

Keep reading

More from the blog.

Every post

Next

Building this? Say hello.

A question about this post, a pattern you would build differently, or the next thing you want written out: Behnia reads every message.