You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Microsoft SQL Server Database Provider - Full-Text Search - EF Core
3
+
description: Using full-text search with the Entity Framework Core Microsoft SQL Server database provider
4
+
author: roji
5
+
ms.date: 02/05/2026
6
+
uid: core/providers/sql-server/full-text-search
7
+
---
8
+
# Full-Text Search in the SQL Server EF Core Provider
9
+
10
+
SQL Server provides [full-text search](/sql/relational-databases/search/full-text-search) capabilities that enable sophisticated text search beyond simple `LIKE` patterns. Full-text search supports linguistic matching, inflectional forms, proximity search, and weighted ranking.
11
+
12
+
EF Core's SQL Server provider supports both full-text search *predicates* (for filtering) and *table-valued functions* (for filtering with ranking).
13
+
14
+
## Setting up full-text search
15
+
16
+
Before using full-text search, you must:
17
+
18
+
1.**Create a full-text catalog** on your database
19
+
2.**Create a full-text index** on the columns you want to search
20
+
21
+
This setup is done at the SQL Server level and is outside the scope of EF Core. For more information, see the [SQL Server full-text search documentation](/sql/relational-databases/search/get-started-with-full-text-search).
22
+
23
+
## Full-text predicates
24
+
25
+
EF Core supports the `FREETEXT()` and `CONTAINS()` predicates, which are used in `Where()` clauses to filter results.
26
+
27
+
### FREETEXT()
28
+
29
+
`FREETEXT()` performs a less strict matching, searching for words based on their meaning, including inflectional forms (such as verb tenses and noun plurals):
`CONTAINS()` performs more precise matching and supports more sophisticated search criteria, including prefix terms, proximity search, and weighted terms:
For more information on `CONTAINS()` query syntax, see the [SQL Server CONTAINS documentation](/sql/t-sql/queries/contains-transact-sql).
83
+
84
+
## Full-text table-valued functions
85
+
86
+
> [!NOTE]
87
+
> Full-text table-valued functions are being introduced in EF Core 11.
88
+
89
+
While the predicates above are useful for filtering, they don't provide ranking information. SQL Server's table-valued functions [`FREETEXTTABLE()`](/sql/relational-databases/system-functions/freetexttable-transact-sql) and [`CONTAINSTABLE()`](/sql/relational-databases/system-functions/containstable-transact-sql) return both matching rows and a ranking score that indicates how well each row matches the search query.
90
+
91
+
### FreeTextTable()
92
+
93
+
`FreeTextTable()` is the table-valued function version of `FreeText()`. It returns `FullTextSearchResult<TEntity>`, which includes both the entity and the ranking value:
Console.WriteLine($"Article {result.Article.Id} with rank {result.Rank}");
108
+
}
109
+
```
110
+
111
+
Note that you must provide the generic type parameters; `Article` corresponds to the entity type being searched, where `int` is the full-text search key specified when creating the index, and which is returned by `FREETEXTTABLE()`.
112
+
113
+
The above automatically searches across all columns registered for full-text searching and returns the top 10 matches. You can also provide a specific column to search:
`ContainsTable()` is the table-valued function version of `Contains()`, supporting the same sophisticated search syntax while also providing ranking information:
139
+
140
+
```csharp
141
+
varresults=awaitcontext.Articles
142
+
.Join(
143
+
context.Articles.ContainsTable<Article, int>( "veggies OR fruits"),
144
+
a=>a.Id,
145
+
ftt=>ftt.Key,
146
+
(a, ftt) =>new { Article=a, ftt.Rank })
147
+
.OrderByDescending(r=>r.Rank)
148
+
.ToListAsync();
149
+
```
150
+
151
+
### Limiting results
152
+
153
+
Both table-valued functions support a `topN` parameter to limit the number of results:
Performance for large result sets | Better for filtering | Better for ranking and sorting
180
+
Combine with other entities | Via joins | Built-in entity result
181
+
Use in `Where()` clause | ✅ Yes | ❌ No (use as a source)
182
+
183
+
Use predicates when you simply need to filter results based on full-text search criteria. Use table-valued functions when you need ranking information to order results by relevance or display relevance scores to users.
# Vector search in the SQL Server EF Core Provider
9
9
10
-
## Vector search
11
-
12
10
> [!NOTE]
13
11
> Vector support was introduced in EF Core 10.0, and is only supported with SQL Server 2025 and above.
14
12
15
-
The SQL Server vector data type allows storing *embeddings*, which are representation of meaning that can be efficiently searched over for similarity, powering AI workloads such as semantic search and retrieval-augmented generation (RAG).
13
+
The SQL Server vector data type allows storing *embeddings*, which are representations of meaning that can be efficiently searched over for similarity, powering AI workloads such as semantic search and retrieval-augmented generation (RAG).
14
+
15
+
## Setting up vector properties
16
16
17
17
To use the `vector` data type, simply add a .NET property of type `SqlVector<float>` to your entity type, specifying the dimensions as follows:
Once your property is added and the corresponding column created in the database, you can start inserting embeddings. Embedding generation is done outside of the database, usually via a service, and the details for doing this are out of scope for this documentation. However, [the .NET Microsoft.Extensions.AI libraries](/dotnet/ai/microsoft-extensions-ai) contains [`IEmbeddingGenerator`](/dotnet/ai/microsoft-extensions-ai#create-embeddings), which is an abstraction over embedding generators that has implementations for the major providers.
51
+
Once your property is added and the corresponding column created in the database, you can start inserting embeddings. Embedding generation is done outside of the database, usually via a service, and the details for doing this are out of scope for this documentation. However, [the .NET Microsoft.Extensions.AI library](/dotnet/ai/microsoft-extensions-ai) contains [`IEmbeddingGenerator`](/dotnet/ai/microsoft-extensions-ai#create-embeddings), which is an abstraction over embedding generators that has implementations for the major providers.
52
52
53
-
Once you've chosen your embedding generator and set it up, use it to generate embeddings and insert them as follows
53
+
Once you've chosen your embedding generator and set it up, use it to generate embeddings and insert them as follows:
54
54
55
55
```c#
56
56
IEmbeddingGenerator<string, Embedding<float>>embeddingGenerator=/* Set up your preferred embedding generator */;
@@ -64,17 +64,156 @@ context.Blogs.Add(new Blog
64
64
awaitcontext.SaveChangesAsync();
65
65
```
66
66
67
-
Finally, use the [`EF.Functions.VectorDistance()`](/sql/t-sql/functions/vector-distance-transact-sql) function to perform similarity search for a given user query:
67
+
Once you have embeddings saved to your database, you're ready to perform vector similarity search over them.
68
+
69
+
## Exact search with VECTOR_DISTANCE()
70
+
71
+
The [`EF.Functions.VectorDistance()`](/sql/t-sql/functions/vector-distance-transact-sql) function computes the *exact* distance between two vectors. Use it to perform similarity search for a given user query:
68
72
69
73
```c#
70
74
varsqlVector=newSqlVector<float>(awaitembeddingGenerator.GenerateVectorAsync("Some user query to be vectorized"));
This function computes the distance between the query vector and every row in the table, then returns the closest matches. While this provides perfectly accurate results, it can be slow for large datasets because SQL Server must scan all rows and compute distances for each one.
82
+
77
83
> [!NOTE]
78
84
> The built-in support in EF 10 replaces the previous [EFCore.SqlServer.VectorSearch](https://github.com/efcore/EFCore.SqlServer.VectorSearch) extension, which allowed performing vector search before the `vector` data type was introduced. As part of upgrading to EF 10, remove the extension from your projects.
79
-
>
80
-
> The [`VECTOR_SEARCH()`](/sql/t-sql/functions/vector-search-transact-sql) function (in preview) for approximate search with DiskANN is currently unsupported.
85
+
86
+
## Approximate search with VECTOR_SEARCH()
87
+
88
+
> [!WARNING]
89
+
> `VECTOR_SEARCH()` and vector indexes are currently experimental features in SQL Server and are subject to change. The APIs in EF Core for these features are also subject to change.
90
+
91
+
For large datasets, computing exact distances for every row can be prohibitively slow. SQL Server 2025 introduces support for *approximate* search through a [vector index](/sql/t-sql/statements/create-vector-index-transact-sql), which provides much better performance at the expense of returning items that are approximately similar - rather than exactly similar - to the query.
92
+
93
+
### Vector indexes
94
+
95
+
To use `VECTOR_SEARCH()`, you must create a vector index on your vector column. Use the `HasVectorIndex()` method in your model configuration:
The following distance metrics are supported for vector indexes:
114
+
115
+
Metric | Description
116
+
----------- | -----------
117
+
`cosine` | Cosine similarity (angular distance)
118
+
`euclidean` | Euclidean distance (L2 norm)
119
+
`dot` | Dot product (negative inner product)
120
+
121
+
Choose the metric that best matches your embedding model and use case. Cosine similarity is commonly used for text embeddings, while euclidean distance is often used for image embeddings.
122
+
123
+
### Searching with VECTOR_SEARCH()
124
+
125
+
Once you have a vector index, use the `VectorSearch()` extension method on your `DbSet`:
This allows you to filter on the similarity score, present it to users, etc.
158
+
159
+
## Hybrid search
160
+
161
+
*Hybrid search* combines vector similarity search with traditional [full-text search](xref:core/providers/sql-server/full-text-search) to deliver more relevant results. Vector search excels at finding semantically similar content, while full-text search is better at exact keyword matching. By combining both approaches and using Reciprocal Rank Fusion (RRF) to merge the results, you can build more intelligent search experiences.
162
+
163
+
The following example shows how to implement hybrid search using EF Core, combining `FreeTextTable()` and `VectorSearch()` in a single query:
2. Performs a vector search on `Article` and combines the results to the full-text search results via a LEFT JOIN
200
+
3. Calculates the RRF score by combining both the full text and the semantic ranking
201
+
4. Orders by RRF score, takes the desired number of results and projects out the original `Article` entities.
202
+
203
+
> [!NOTE]
204
+
> Rather than using a LEFT JOIN, a FULL OUTER JOIN would be more suitable for this scenario; this would allow highly-ranking results from either search side to be included in the final result, even if that result does not appear at all on the other side. With the above LEFT JOIN approach, if a result has a very high vector similarity score, it never gets included in the final result if that result doesn't also have a high full-text score. However, EF doesn't currently support FULL OUTER JOIN; upvote [#37633](https://github.com/dotnet/efcore/issues/37633) if this is something you'd like to see supported.
0 commit comments