Skip to content

Commit 6e20070

Browse files
committed
added basic example of fts and hs in whats new,
added small mention of hs in the vector section, other minor cleanup
1 parent 2a5f88e commit 6e20070

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

entity-framework/core/providers/cosmos/full-text-search.md

-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ You can also set a default language for the container - unless overridden in the
7373
}
7474
```
7575

76-
> [!NOTE]
77-
> Configuring the index is not mandatory, but it is recommended as it greatly improves performance of full-text search queries.
78-
7976
## Querying
8077

8178
As part of the full-text search feature, Azure Cosmos DB introduced several built-in functions which allow for efficient querying of content inside the full-text search enabled properties. These functions are: [`FullTextContains`](/azure/cosmos-db/nosql/query/fulltextcontains), [`FullTextContainsAll`](/azure/cosmos-db/nosql/query/fulltextcontainsall), [`FullTextContainsAny`](/azure/cosmos-db/nosql/query/fulltextcontainsany), which look for specific keyword or keywords and [`FullTextScore`](/azure/cosmos-db/nosql/query/fulltextscore), which returns [BM25 score](https://en.wikipedia.org/wiki/Okapi_BM25) based on provided keywords.

entity-framework/core/providers/cosmos/vector-search.md

+6
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,9 @@ var blogs = await context.Blogs
5353
```
5454

5555
This will returns the top five Blogs, based on the similarity of their `Vector` property and the externally-provided `anotherVector` data.
56+
57+
## Hybrid search
58+
59+
Vector similarity search can be used with full-text search in the same query (i.e. hybrid search), by combining results of `VectorDistance` and `FullTextScore` functions using the [`RRF`](/azure/cosmos-db/nosql/query/rrf) (Reciprocal Rank Fusion) function.
60+
61+
See [documentation](xref:core/providers/cosmos/full-text-search?#hybrid-search) to learn how to enable full-text search support in EF model and how to use hybrid search in queries.

entity-framework/core/what-is-new/ef-core-10.0/whatsnew.md

+49-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,55 @@ EF10 requires the .NET 10 SDK to build and requires the .NET 10 runtime to run.
2626
### Full-text search support
2727

2828
Azure Cosmos DB now offers support for [full-text search](/azure/cosmos-db/gen-ai/full-text-search). It enables efficient and effective text searches, as well as evaluating the relevance of documents to a given search query. It can be used in combination with vector search to improve the accuracy of responses in some AI scenarios.
29-
EF Core 10 is adding support for this feature allowing for modeling the database with full-text search enabled properties and using full-text search functions inside queries targeting Azure Cosmos DB. See [documentation](xref:core/providers/cosmos/full-text-search) to learn how to take advantage of full-text search using EF Core.
29+
EF Core 10 is adding support for this feature allowing for modeling the database with full-text search enabled properties and using full-text search functions inside queries targeting Azure Cosmos DB.
30+
31+
Here is a basic EF model configuration enabling full-text search on one of the properties:
32+
33+
```c#
34+
public class Blog
35+
{
36+
...
37+
38+
public string Contents { get; set; }
39+
}
40+
41+
public class BloggingContext
42+
{
43+
...
44+
45+
protected override void OnModelCreating(ModelBuilder modelBuilder)
46+
{
47+
modelBuilder.Entity<Blog>(b =>
48+
{
49+
b.Property(x => x.Contents).EnableFullTextSearch();
50+
b.HasIndex(x => x.Contents).IsFullTextIndex();
51+
});
52+
}
53+
}
54+
```
55+
56+
Once the model is configured, we can use full-text search operations in queries using methods provided in `EF.Functions`:
57+
58+
```c#
59+
var cosmosBlogs = await context.Blogs.Where(x => EF.Functions.FullTextContains(x.Contents, "cosmos")).ToListAsync();
60+
```
61+
62+
The following full-text operations are currently supported: [`FullTextContains`](/azure/cosmos-db/nosql/query/fulltextcontains), [`FullTextContainsAll`](/azure/cosmos-db/nosql/query/fulltextcontainsall), [`FullTextContainsAny`](/azure/cosmos-db/nosql/query/fulltextcontainsany), [`FullTextScore`](/azure/cosmos-db/nosql/query/fulltextscore).
63+
64+
#### Hybrid search
65+
66+
EF Core also supports [`RRF`](/azure/cosmos-db/nosql/query/rrf) (Reciprocal Rank Fusion) function, which combines vector similarity search and full-text search (i.e. hybrid search). Here is an example query using hybrid search:
67+
68+
```c#
69+
float[] myVector = /* generate vector data from text, image, etc. */
70+
var hybrid = await context.Blogs.OrderBy(x => EF.Functions.Rrf(
71+
EF.Functions.FullTextScore(x.Contents, "database"),
72+
EF.Functions.VectorDistance(x.Vector, myVector)))
73+
.Take(10)
74+
.ToListAsync();
75+
```
76+
77+
See [documentation](xref:core/providers/cosmos/full-text-search) to learn more on how to use full-text search with EF Core.
3078

3179
### Vector similarity search exits preview
3280

0 commit comments

Comments
 (0)