Lesson 4 of 5 Vector Search

Vector Index Types and Metrics

This lesson explains the DiskANN index type, metric selection, index versions and maintenance.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe the DiskANN vector index.
  • Choose a metric for an embedding model.
  • Explain the behaviour of current and earlier index versions.

DiskANN index type

SQL vector indexes use DiskANN, currently the only supported type and the default for TYPE. DiskANN builds a navigable graph that is stored on disk with compressed (quantized) vectors, so large indexes do not need to fit in memory and searches read few pages. CREATE VECTOR INDEX requires ALTER permission on the table, accepts MAXDOP to limit build parallelism and can be placed on a filegroup in SQL Server. Vector indexes and VECTOR_SEARCH are generally available in Azure SQL Database, SQL database in Fabric and Azure SQL Managed Instance with the Always-up-to-date policy, and in preview in SQL Server 2025, where PREVIEW_FEATURES must be on.

True or false

DiskANN indexes

Exam skills 3.2.6

Decide whether each statement about SQL vector indexes is true.

Log in to try this activity Interactive activities are free with an account.

Choosing the metric

The index's METRIC must match the metric that queries use; otherwise the query cannot use the index, raises a warning and falls back to kNN. The metric should be the one the embedding model is designed for, as the following table summarizes.

MetricChoose when
cosineMost text embedding models, including Azure OpenAI; direction matters, length does not
dotVectors are normalized (then equivalent to cosine and slightly cheaper), or the model is trained for dot product
euclideanVector length carries meaning, such as some image or numeric feature embeddings

Creating one index per metric is not useful: queries should consistently use the model's metric.

Scenario questions

Index metric

Exam skills 3.2.6

Choose the vector index metric for each case.

Log in to try this activity Interactive activities are free with an account.

Index versions, DML and maintenance

Indexes created with the current version support full DML: inserts, updates, deletes and MERGE are reflected after commit through automatic background maintenance, which sys.dm_db_vector_indexes reports on. Indexes created with earlier versions made tables read-only (unless the ALLOW_STALE_VECTOR_INDEX configuration allowed stale results), used post-filtering and required TOP_N; they are deprecated and must be dropped and recreated, which sys.vector_indexes.build_parameters (Version 3 or later) helps identify. Other limits apply: vector indexes cannot be partitioned, are not replicated to subscribers, block TRUNCATE TABLE, and are not deployed by a dacpac when the table has fewer than 100 vectors. After replacing most embeddings, such as when re-embedding with a new model, the index should be rebuilt so its graph matches the new distribution, and datasets with many duplicate vectors should be deduplicated.

Select all that apply

Maintaining vector indexes

Exam skills 3.2.6

Identify the true statements about vector index maintenance.

Log in to try this activity Interactive activities are free with an account.
Worked example

An index that is not used

A developer creates a vector index with METRIC = 'euclidean' on Azure OpenAI embeddings, while the application's queries use VECTOR_SEARCH with METRIC = 'cosine' and TOP WITH APPROXIMATE. Queries are slow and return a warning. What should the developer do?

Drop the index and recreate it with METRIC = 'cosine', the metric the queries use and the one appropriate for Azure OpenAI text embeddings. A query can use only an index with the same metric on the same column, so the current queries fall back to kNN. Changing the queries to euclidean would use the index, and because Azure OpenAI vectors are normalized the ranking would match cosine, but keeping the model's standard metric across code and index is clearer.

Check yourself

How many rows with non-NULL vectors does a table need before a vector index can be created?

Show answer

At least 100.

Exam Tips

Remember for the exam

  • DiskANN is the only vector index type; it stores the graph on disk.
  • Index metric must match the query metric, or kNN is used with a warning.
  • Current indexes support DML; older-version indexes should be recreated.
  • Rebuild after replacing most embeddings; at least 100 vectors to create.