Vector Search with EF Core and SQL Server 2025: A Practical Guide
Author's note: SQL Server 2025 introduces a first-class vector data type and a family of vector functions. EF Core 10 added native LINQ translation for these features; EF Core 11 extends support to approximate search using vector indexes. This article walks through both, with runnable C# examples.
Table of contents
- Why vector search matters
- What's new in SQL Server 2025
- Prerequisites
- Defining a vector property in your EF model
- Generating embeddings and inserting them
- Exact search with
VECTOR_DISTANCE() - Creating a vector index
- Approximate search with
VECTOR_SEARCH() - Hybrid search (vector + full-text)
- Pure T-SQL reference
- Performance and design tips
1. Why vector search matters
Modern AI workloads — semantic search, recommendation systems, retrieval-augmented generation (RAG) — depend on representing text, images, or audio as dense numeric arrays called embeddings. Two embeddings that are close in vector space represent similar meaning. Until recently, storing those embeddings in SQL Server required JSON columns, custom UDFs, or a separate vector database. SQL Server 2025 removes that friction: vectors are now a first-class column type, with built-in distance functions and (in preview) approximate indexes.
2. What's new in SQL Server 2025
| Feature | Description | Status |
|---|---|---|
VECTOR(n) data type | Stores a fixed-dimension array of float32 (or float16 for half-precision). Up to 1998 dimensions for float32, up to 3996 for float16. | GA |
VECTOR_DISTANCE | Computes the exact distance between two vectors using cosine, euclidean, or dot metrics. | GA |
VECTOR_NORM | Returns the magnitude (length) of a vector. | GA |
VECTOR_NORMALIZE | Returns a unit-length vector. | GA |
VECTORPROPERTY | Returns metadata for a vector (e.g. dimensions, base type). | GA |
CREATE VECTOR INDEX | Builds an approximate nearest-neighbor index on a vector column. | Preview |
VECTOR_SEARCH | Table-valued function that performs approximate nearest-neighbor search using a vector index. | Preview |
Preview features.CREATE VECTOR INDEXandVECTOR_SEARCHare in preview and require enablingPREVIEW_FEATURESat the database scope. APIs may change.
3. Prerequisites
- SQL Server 2025 (17.x) or Azure SQL Database
- .NET 10 (or later)
- EF Core 10 for exact search; EF Core 11 for vector indexes & approximate search
- An embedding generator — for example
Microsoft.Extensions.AIwrapping Azure OpenAI, OpenAI, or a local model
NuGet packages
4. Defining a vector property in your EF model
Add a property of type SqlVector<float> to your entity. The dimension count must match what your embedding model produces (for example, 1536 for text-embedding-ada-002, 3072 for text-embedding-3-large).
Using Data Annotations
Using the Fluent API
EF Core 11 behavior change. Vector columns are no longer materialized by default when loading entities, because they are large and rarely needed when reading. They are only fetched when explicitly projected or used in a query expression.
5. Generating embeddings and inserting them
Embedding generation happens outside the database. The Microsoft.Extensions.AI abstractions hide provider-specific details behind IEmbeddingGenerator<string, Embedding<float>>.
6. Exact search with VECTOR_DISTANCE()
For small and mid-sized datasets (a rule of thumb is < 50,000 candidate rows after filtering), an exact k-nearest-neighbors scan is simple and accurate. EF Core translates EF.Functions.VectorDistance(...) to the T-SQL VECTOR_DISTANCE function.
The supported metrics are cosine, euclidean, and dot. Pick the metric that matches how your embedding model was trained — most text models (OpenAI, Azure OpenAI, MiniLM, BGE) are tuned for cosine similarity.
7. Creating a vector index
For larger tables, an exact scan becomes too slow. SQL Server 2025 introduces an approximate nearest-neighbor index. EF Core 11 exposes HasVectorIndex():
This generates a migration containing:
Enable preview features first. Before applying the migration, run ALTER DATABASE SCOPED CONFIGURATION SET PREVIEW_FEATURES = ON; against the target database.8. Approximate search with VECTOR_SEARCH()
Once the index exists, use the VectorSearch() extension on your DbSet. The result is a VectorSearchResult<TEntity> exposing both the entity and its computed distance.
EF Core translates this to the table-valued function:
9. Hybrid search (vector + full-text)
Vector search excels at semantic matches; full-text search excels at exact keyword matches. Combining both with Reciprocal Rank Fusion (RRF) gives more relevant results than either alone.
Tip. AFULL OUTER JOINbetween the two ranked sets is the most accurate fusion strategy because it includes documents that score highly on either side. EF Core does not yet supportFULL OUTER JOINin LINQ; today, aLEFT JOINfrom the full-text side or raw SQL is the practical workaround.
10. Pure T-SQL reference
If you prefer working directly in T-SQL — for instance, from a stored procedure that EF Core then calls via FromSqlRaw() — the same building blocks look like this.
Declaring and casting vectors
Exact kNN with VECTOR_DISTANCE
Approximate kNN with VECTOR_SEARCH
ORDER BY rules forVECTOR_SEARCH. When usingSELECT TOP (N) WITH APPROXIMATE, the query must include anORDER BYreferencing only thedistancecolumn, in ascending order.
11. Performance and design tips
- Match dimensions exactly. The column dimension and the embedding produced by your generator must agree, or inserts will fail.
- Pick the right metric. Cosine for normalized text embeddings; Euclidean often works for image embeddings; dot product when you control normalization yourself.
- Don't read vectors back unless you need them. EF Core 11 already excludes them from
SELECT *materialization — keep it that way. - Use exact search up to roughly 50,000 candidate rows after applying business filters; switch to a vector index above that scale.
- Half-precision saves 50% of storage. Declare
vector(1536, float16)when bytes matter and a small accuracy loss is acceptable. - Combine with relational filters. SQL Server 2025 applies predicates iteratively during vector search, so
WHEREclauses andVECTOR_SEARCHcompose without you having to oversample. - Cache embeddings. Embedding generation is the slowest and most expensive part of the pipeline; cache outputs by content hash.
Wrap-up
SQL Server 2025 plus EF Core 10/11 lets you keep your operational data and your AI search index in the same database, with a familiar LINQ surface and migrations support. Start with EF.Functions.VectorDistance() to validate the approach against your data, then add a vector index and switch to VectorSearch() as you scale.
References (Microsoft Learn)
- What's New in EF Core 10 — Vector search support
- What's New in EF Core 11 —
VECTOR_SEARCH()and vector indexes - Vector search in the SQL Server EF Core Provider
- VECTOR_DISTANCE (Transact-SQL)
- VECTOR_SEARCH (Transact-SQL) (Preview)
- Vector data type
- Vector search and vector indexes in the SQL Database Engine
- Vector datatype support in SqlClient
- What's new in SQL Server 2025