Skip to content

Commit f1e0268

Browse files
committed
Cosmos docs leftovers for 10 (#5086)
1 parent e12eb44 commit f1e0268

File tree

3 files changed

+78
-75
lines changed

3 files changed

+78
-75
lines changed

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

Lines changed: 41 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -46,34 +46,34 @@ public class BloggingContext
4646
Full-text search operations are language specific, using American English (`en-US`) by default. You can customize the language for individual properties as part of `EnableFullTextSearch` call:
4747

4848
```c#
49-
protected override void OnModelCreating(ModelBuilder modelBuilder)
49+
protected override void OnModelCreating(ModelBuilder modelBuilder)
50+
{
51+
modelBuilder.Entity<Blog>(b =>
5052
{
51-
modelBuilder.Entity<Blog>(b =>
52-
{
53-
b.Property(x => x.Contents).EnableFullTextSearch();
54-
b.HasIndex(x => x.Contents).IsFullTextIndex();
55-
b.Property(x => x.ContentsGerman).EnableFullTextSearch("de-DE");
56-
b.HasIndex(x => x.ContentsGerman).IsFullTextIndex();
57-
});
58-
}
53+
b.Property(x => x.Contents).EnableFullTextSearch();
54+
b.HasIndex(x => x.Contents).IsFullTextIndex();
55+
b.Property(x => x.ContentsGerman).EnableFullTextSearch("de-DE");
56+
b.HasIndex(x => x.ContentsGerman).IsFullTextIndex();
57+
});
58+
}
5959
```
6060

6161
You can also set a default language for the container - unless overridden in the `EnableFullTextSearch` method, all full-text properties inside the container will use that language.
6262

6363
```c#
64-
protected override void OnModelCreating(ModelBuilder modelBuilder)
64+
protected override void OnModelCreating(ModelBuilder modelBuilder)
65+
{
66+
modelBuilder.Entity<Blog>(b =>
6567
{
66-
modelBuilder.Entity<Blog>(b =>
67-
{
68-
b.HasDefaultFullTextLanguage("de-DE");
69-
b.Property(x => x.ContentsEnglish).EnableFullTextSearch("en-US");
70-
b.HasIndex(x => x.ContentsEnglish).IsFullTextIndex();
71-
b.Property(x => x.ContentsGerman).EnableFullTextSearch();
72-
b.HasIndex(x => x.ContentsGerman).IsFullTextIndex();
73-
b.Property(x => x.TagsGerman).EnableFullTextSearch();
74-
b.HasIndex(x => x.TagsGerman).IsFullTextIndex();
75-
});
76-
}
68+
b.HasDefaultFullTextLanguage("de-DE");
69+
b.Property(x => x.ContentsEnglish).EnableFullTextSearch("en-US");
70+
b.HasIndex(x => x.ContentsEnglish).IsFullTextIndex();
71+
b.Property(x => x.ContentsGerman).EnableFullTextSearch();
72+
b.HasIndex(x => x.ContentsGerman).IsFullTextIndex();
73+
b.Property(x => x.TagsGerman).EnableFullTextSearch();
74+
b.HasIndex(x => x.TagsGerman).IsFullTextIndex();
75+
});
76+
}
7777
```
7878

7979
## Querying
@@ -94,41 +94,33 @@ var mostInteresting = await context.Blogs.OrderBy(x => EF.Functions.FullTextScor
9494

9595
## Hybrid search
9696

97-
Full-text search can be used with vector search in the same query (i.e. hybrid search), by combining results of `FullTextScore` and `VectorDistance` functions. It can be done using the [`RRF`](/azure/cosmos-db/nosql/query/rrf) (Reciprocal Rank Fusion) function, which EF Core also provides inside `EF.Functions`:
97+
Full-text search can be used with [vector search](xref:core/providers/cosmos/vector-search) in the same query; this is sometimes known as "hybrid search", and involves combining the scoring results from multiple searches via the [RRF (Reciprocal Rank Fusion) function](/azure/cosmos-db/nosql/query/rrf). Once you have your vector and full-text search configuration properly set up, you can perform hybrid search as follows:
9898

9999
```c#
100-
public class Blog
101-
{
102-
...
103-
104-
public float[] Vector { get; set; }
105-
public string Contents { get; set; }
106-
}
107-
108-
public class BloggingContext
109-
{
110-
...
111-
112-
protected override void OnModelCreating(ModelBuilder modelBuilder)
113-
{
114-
modelBuilder.Entity<Blog>(b =>
115-
{
116-
b.Property(x => x.Contents).EnableFullTextSearch();
117-
b.HasIndex(x => x.Contents).IsFullTextIndex();
118-
119-
b.Property(x => x.Vector).IsVectorProperty(DistanceFunction.Cosine, dimensions: 1536);
120-
b.HasIndex(x => x.Vector).IsVectorIndex(VectorIndexType.Flat);
121-
});
122-
}
123-
}
124-
125100
float[] myVector = /* generate vector data from text, image, etc. */
126-
var hybrid = await context.Blogs.OrderBy(x => EF.Functions.Rrf(
101+
var hybrid = await context.Blogs
102+
.OrderBy(x => EF.Functions.Rrf(
127103
EF.Functions.FullTextScore(x.Contents, "database"),
128104
EF.Functions.VectorDistance(x.Vector, myVector)))
129105
.Take(10)
130106
.ToListAsync();
131107
```
132108

109+
The RRF function also allows assigning different weights to each search function, allowing e.g. the vector search to have great weight in the overall results:
110+
111+
```c#
112+
float[] myVector = /* generate vector data from text, image, etc. */
113+
var hybrid = await context.Blogs
114+
.OrderBy(x => EF.Functions.Rrf(
115+
new[]
116+
{
117+
EF.Functions.FullTextScore(x.Contents, "database"),
118+
EF.Functions.VectorDistance(x.Vector, myVector)
119+
},
120+
weights: new[] { 1, 2 }))
121+
.Take(10)
122+
.ToListAsync();
123+
```
124+
133125
> [!TIP]
134-
> You can combine more than two scoring functions inside `Rrf` call, as well as using only `FullTextScore`, or only `VectorDistance`.
126+
> You can combine more than two scoring functions inside `Rrf` call, as well as using only `FullTextScore`, or only `VectorDistance` invocations.

entity-framework/core/providers/cosmos/querying.md

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -223,19 +223,19 @@ This section shows which .NET methods and members are translated into which SQL
223223
------------------------------------------ | --------------------------------------------------------------------------------- | --------
224224
DateTime.UtcNow | [GetCurrentDateTime()](/azure/cosmos-db/nosql/query/getcurrentdatetime)
225225
DateTimeOffset.UtcNow | [GetCurrentDateTime()](/azure/cosmos-db/nosql/query/getcurrentdatetime)
226-
dateTime.Year<sup>1</sup> | [DateTimePart("yyyy", dateTime)](/azure/cosmos-db/nosql/query/datetimepart) | EF Core 9.0
227-
dateTimeOffset.Year<sup>1</sup> | [DateTimePart("yyyy", dateTimeOffset)](/azure/cosmos-db/nosql/query/datetimepart) | EF Core 9.0
228-
dateTime.AddYears(years)<sup>1</sup> | [DateTimeAdd("yyyy", dateTime)](/azure/cosmos-db/nosql/query/datetimeadd) | EF Core 9.0
229-
dateTimeOffset.AddYears(years)<sup>1</sup> | [DateTimeAdd("yyyy", dateTimeOffset)](/azure/cosmos-db/nosql/query/datetimeadd) | EF Core 9.0
226+
dateTime.Year<sup>1</sup> | [DateTimePart("yyyy", dateTime)](/azure/cosmos-db/nosql/query/datetimepart) | EF 9
227+
dateTimeOffset.Year<sup>1</sup> | [DateTimePart("yyyy", dateTimeOffset)](/azure/cosmos-db/nosql/query/datetimepart) | EF 9
228+
dateTime.AddYears(years)<sup>1</sup> | [DateTimeAdd("yyyy", dateTime)](/azure/cosmos-db/nosql/query/datetimeadd) | EF 9
229+
dateTimeOffset.AddYears(years)<sup>1</sup> | [DateTimeAdd("yyyy", dateTimeOffset)](/azure/cosmos-db/nosql/query/datetimeadd) | EF 9
230230

231231
<sup>1</sup> The other component members are translated as well (Month, Day...).
232232

233233
### Numeric functions
234234

235-
.NET | SQL | Added in
236-
-------------------------- | --------------------------------------------------- | --------
237-
double.DegreesToRadians(x) | [RADIANS(@x)](/azure/cosmos-db/nosql/query/radians) | EF Core 8.0
238-
double.RadiansToDegrees(x) | [DEGREES(@x)](/azure/cosmos-db/nosql/query/degrees) | EF Core 8.0
235+
.NET | SQL
236+
-------------------------- | ---------------------------------------------------
237+
double.DegreesToRadians(x) | [RADIANS(@x)](/azure/cosmos-db/nosql/query/radians)
238+
double.RadiansToDegrees(x) | [DEGREES(@x)](/azure/cosmos-db/nosql/query/degrees)
239239
EF.Functions.Random() | [RAND()](/azure/cosmos-db/nosql/query/rand)
240240
Math.Abs(value) | [ABS(@value)](/azure/cosmos-db/nosql/query/abs)
241241
Math.Acos(d) | [ACOS(@d)](/azure/cosmos-db/nosql/query/acos)
@@ -266,17 +266,17 @@ Math.Truncate(d) | [TRUNC(@d)](/azure/cosmos-db/nosql/query/trunc)
266266

267267
.NET | SQL | Added in
268268
----------------------------------------------------------------- | ---------------------------------------------------------------------------------- | --------
269-
Regex.IsMatch(input, pattern) | [RegexMatch(@pattern, @input)](/azure/cosmos-db/nosql/query/regexmatch) | EF Core 7.0
270-
Regex.IsMatch(input, pattern, options) | [RegexMatch(@input, @pattern, @options)](/azure/cosmos-db/nosql/query/regexmatch) | EF Core 7.0
269+
Regex.IsMatch(input, pattern) | [RegexMatch(@pattern, @input)](/azure/cosmos-db/nosql/query/regexmatch)
270+
Regex.IsMatch(input, pattern, options) | [RegexMatch(@input, @pattern, @options)](/azure/cosmos-db/nosql/query/regexmatch)
271271
string.Concat(str0, str1) | @str0 + @str1
272272
string.Equals(a, b, StringComparison.Ordinal) | [STRINGEQUALS(@a, @b)](/azure/cosmos-db/nosql/query/stringequals)
273273
string.Equals(a, b, StringComparison.OrdinalIgnoreCase) | [STRINGEQUALS(@a, @b, true)](/azure/cosmos-db/nosql/query/stringequals)
274274
stringValue.Contains(value) | [CONTAINS(@stringValue, @value)](/azure/cosmos-db/nosql/query/contains)
275-
stringValue.Contains(value, StringComparison.Ordinal) | [CONTAINS(@stringValue, @value, false)](/azure/cosmos-db/nosql/query/contains) | EF Core 9.0
276-
stringValue.Contains(value, StringComparison.OrdinalIgnoreCase) | [CONTAINS(@stringValue, @value, true)](/azure/cosmos-db/nosql/query/contains) | EF Core 9.0
275+
stringValue.Contains(value, StringComparison.Ordinal) | [CONTAINS(@stringValue, @value, false)](/azure/cosmos-db/nosql/query/contains) | EF 9
276+
stringValue.Contains(value, StringComparison.OrdinalIgnoreCase) | [CONTAINS(@stringValue, @value, true)](/azure/cosmos-db/nosql/query/contains) | EF 9
277277
stringValue.EndsWith(value) | [ENDSWITH(@stringValue, @value)](/azure/cosmos-db/nosql/query/endswith)
278-
stringValue.EndsWith(value, StringComparison.Ordinal) | [ENDSWITH(@stringValue, @value, false)](/azure/cosmos-db/nosql/query/endswith) | EF Core 9.0
279-
stringValue.EndsWith(value, StringComparison.OrdinalIgnoreCase) | [ENDSWITH(@stringValue, @value, true)](/azure/cosmos-db/nosql/query/endswith) | EF Core 9.0
278+
stringValue.EndsWith(value, StringComparison.Ordinal) | [ENDSWITH(@stringValue, @value, false)](/azure/cosmos-db/nosql/query/endswith) | EF 9
279+
stringValue.EndsWith(value, StringComparison.OrdinalIgnoreCase) | [ENDSWITH(@stringValue, @value, true)](/azure/cosmos-db/nosql/query/endswith) | EF 9
280280
stringValue.Equals(value, StringComparison.Ordinal) | [STRINGEQUALS(@stringValue, @value)](/azure/cosmos-db/nosql/query/stringequals)
281281
stringValue.Equals(value, StringComparison.OrdinalIgnoreCase) | [STRINGEQUALS(@stringValue, @value, true)](/azure/cosmos-db/nosql/query/stringequals)
282282
stringValue.FirstOrDefault() | [LEFT(@stringValue, 1)](/azure/cosmos-db/nosql/query/left)
@@ -286,8 +286,8 @@ stringValue.LastOrDefault() | [RIGHT(@stri
286286
stringValue.Length | [LENGTH(@stringValue)](/azure/cosmos-db/nosql/query/length)
287287
stringValue.Replace(oldValue, newValue) | [REPLACE(@stringValue, @oldValue, @newValue)](/azure/cosmos-db/nosql/query/replace)
288288
stringValue.StartsWith(value) | [STARTSWITH(@stringValue, @value)](/azure/cosmos-db/nosql/query/startswith)
289-
stringValue.StartsWith(value, StringComparison.Ordinal) | [STARTSWITH(@stringValue, @value, false)](/azure/cosmos-db/nosql/query/startswith) | EF Core 9.0
290-
stringValue.StartsWith(value, StringComparison.OrdinalIgnoreCase) | [STARTSWITH(@stringValue, @value, true)](/azure/cosmos-db/nosql/query/startswith) | EF Core 9.0
289+
stringValue.StartsWith(value, StringComparison.Ordinal) | [STARTSWITH(@stringValue, @value, false)](/azure/cosmos-db/nosql/query/startswith) | EF 9
290+
stringValue.StartsWith(value, StringComparison.OrdinalIgnoreCase) | [STARTSWITH(@stringValue, @value, true)](/azure/cosmos-db/nosql/query/startswith) | EF 9
291291
stringValue.Substring(startIndex) | [SUBSTRING(@stringValue, @startIndex, LENGTH(@stringValue))](/azure/cosmos-db/nosql/query/substring)
292292
stringValue.Substring(startIndex, length) | [SUBSTRING(@stringValue, @startIndex, @length)](/azure/cosmos-db/nosql/query/substring)
293293
stringValue.ToLower() | [LOWER(@stringValue)](/azure/cosmos-db/nosql/query/lower)
@@ -296,17 +296,28 @@ stringValue.Trim() | [TRIM(@strin
296296
stringValue.TrimEnd() | [RTRIM(@stringValue)](/azure/cosmos-db/nosql/query/rtrim)
297297
stringValue.TrimStart() | [LTRIM(@stringValue)](/azure/cosmos-db/nosql/query/ltrim)
298298

299+
### Vector and full-text search
300+
301+
.NET | SQL | Added in
302+
--------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- | -----
303+
EF.Functions.VectorDistance(vector1, vector2). | [VectorDistance(vector1, vector2)](/azure/cosmos-db/nosql/query/vectordistance) | EF 9
304+
EF.Functions.VectorDistance(vector1, vector2, bruteForce) | [VectorDistance(vector1, vector2, bruteForce)](/azure/cosmos-db/nosql/query/vectordistance) | EF 9
305+
EF.Functions.VectorDistance(vector1, vector2, bruteForce, distanceFunction) | [VectorDistance(vector1, vector2, bruteForce, distanceFunction)](/azure/cosmos-db/nosql/query/vectordistance) | EF 9
306+
EF.Functions.FullTextContains(property, keyword) | [FullTextContains(property, keyword)](/azure/cosmos-db/nosql/query/fulltextcontains) | EF 10
307+
EF.Functions.FullTextContainsAll(property, keyword1, keyword2) | [FullTextContainsAll(property, keyword1, keyword2)](/azure/cosmos-db/nosql/query/fulltextcontainsall) | EF 10
308+
EF.Functions.FullTextContainsAny(property, keyword1, keyword2) | [FullTextContainsAny(property, keyword1, keyword2)](/azure/cosmos-db/nosql/query/fulltextcontainsany) | EF 10
309+
EF.Functions.FullTextScore(property, keyword1, keyword2) | [FullTextScore(property, keyword1, keyword2)](/azure/cosmos-db/nosql/query/fulltextscore) | EF 10
310+
EF.Functions.Rrf(search1, search2) | [RRF(property, search1, search2)](/azure/cosmos-db/nosql/query/rrf). | EF 10
311+
EF.Functions.Rrf(new[] { search1, search2 }, weights) | [RRF(property, search1, search2, weights)](/azure/cosmos-db/nosql/query/rrf) | EF 10
312+
313+
For more information on vector search, see [the documentation](xref:core/providers/cosmos/vector-search). For more information on full-text search, see [the documentation](xref:core/providers/cosmos/full-text-search).
314+
299315
### Miscellaneous functions
300316

301-
.NET | SQL | Notes
317+
.NET | SQL | Added in
302318
--------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- | -----
303319
collection.Contains(item) | @item IN @collection
304-
EF.Functions.CoalesceUndefined(x, y)<sup>1</sup> | [x ?? y](/azure/cosmos-db/nosql/query/ternary-coalesce-operators#coalesce-operator) | Added in EF Core 9.0
305-
EF.Functions.IsDefined(x) | [IS_DEFINED(x)](/azure/cosmos-db/nosql/query/is-defined) | Added in EF Core 9.0
306-
EF.Functions.VectorDistance(vector1, vector2)<sup>2</sup> | [VectorDistance(vector1, vector2)](/azure/cosmos-db/nosql/query/vectordistance) | Added in EF Core 9.0, Experimental
307-
EF.Functions.VectorDistance(vector1, vector2, bruteForce)<sup>2</sup> | [VectorDistance(vector1, vector2, bruteForce)](/azure/cosmos-db/nosql/query/vectordistance) | Added in EF Core 9.0, Experimental
308-
EF.Functions.VectorDistance(vector1, vector2, bruteForce, distanceFunction)<sup>2</sup> | [VectorDistance(vector1, vector2, bruteForce, distanceFunction)](/azure/cosmos-db/nosql/query/vectordistance) | Added in EF Core 9.0, Experimental
320+
EF.Functions.CoalesceUndefined(x, y)<sup>1</sup> | [x ?? y](/azure/cosmos-db/nosql/query/ternary-coalesce-operators#coalesce-operator) | EF 9
321+
EF.Functions.IsDefined(x) | [IS_DEFINED(x)](/azure/cosmos-db/nosql/query/is-defined) | EF 9
309322

310323
<sup>1</sup> Note that `EF.Functions.CoalesceUndefined` coalesces `undefined`, not `null`. To coalesce `null`, use the regular C# `??` operator.
311-
312-
<sup>2</sup> [See the documentation](xref:core/providers/cosmos/vector-search) for information on using vector search in Azure Cosmos DB, which is experimental. The APIs are subject to change.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ await context.Blogs.ExecuteUpdateAsync(s =>
9595

9696
| **Breaking change** | **Impact** |
9797
|:----------------------------------------------------------------------------------------------------------|------------|
98-
| [Using GetDateTimeOffset without an offset now assumes UTC](#DateTimeOffset-read) | High |
98+
| [Using GetDateTimeOffset without an offset now assumes UTC](#DateTimeOffset-read) | High |
9999
| [Writing DateTimeOffset into REAL column now writes in UTC](#DateTimeOffset-write) | High |
100-
| [Using GetDateTime with an offset now returns value in UTC](#DateTime-read) | High |
100+
| [Using GetDateTime with an offset now returns value in UTC](#DateTime-read) | High |
101101

102102
### High-impact changes
103103

0 commit comments

Comments
 (0)