Skip to content

Commit 65e21d5

Browse files
committed
RDoc-3280 Update information about similarity threshold in vector search
1 parent 023190e commit 65e21d5

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

Documentation/7.0/Raven.Documentation.Pages/ai-integration/vector-search/vector-search-using-dynamic-query.dotnet.markdown

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,14 @@
131131

132132
* **Minimum similarity**
133133
You can specify the minimum similarity to use when searching for related vectors.
134-
Can be a value between `0.0f` and `1.0f`.
135-
A value closer to `1.0f` requires higher similarity between vectors,
136-
while a value closer to `0.0f` allows for less similarity.
134+
The value can be between `0.0f` and `1.0f`.
135+
* A value closer to `1.0f` requires higher similarity between vectors,
136+
while a value closer to `0.0f` allows for less similarity.
137+
* **Important**: To filter out less relevant results when performing vector search queries,
138+
it is recommended to explicitly specify the minimum similarity level at query time.
137139

138140
If not specified, the default value is taken from the following configuration key:
139-
[Indexing.Corax.VectorSearch.DefaultMinimumSimilarity ](../../server/configuration/indexing-configuration#indexing.corax.vectorsearch.defaultnumberofcandidatesforquerying).
141+
[Indexing.Corax.VectorSearch.DefaultMinimumSimilarity](../../server/configuration/indexing-configuration#indexing.corax.vectorsearch.defaultnumberofcandidatesforquerying).
140142

141143
* **Number of candidates**
142144
You can specify the maximum number of vectors that RavenDB will return from a graph search.
@@ -555,9 +557,7 @@ where vector.search(TagsEmbeddedAsSingle, $queryVector, 0.85, 10)
555557
from "Products"
556558
// The filtering condition:
557559
where (PricePerUnit > $minPrice)
558-
// The vector search here will execute with the default similarity (0.75f)
559-
// and the default NumberOfCandidates (16)
560-
and (vector.search(embedding.text(Name), $searchTerm))
560+
and (vector.search(embedding.text(Name), $searchTerm, 0.75, 16))
561561
{ "minPrice" : 35.0, "searchTerm" : "italian food" }
562562
{CODE-TAB-BLOCK/}
563563
{CODE-TABS/}
@@ -571,7 +571,7 @@ and (vector.search(embedding.text(Name), $searchTerm))
571571
A larger _NumberOfCandidates_ increases the pool of documents considered,
572572
improving the chances of finding results that match both the vector search and the filter condition.
573573

574-
* For example, in the above query, the vector search executes with the default params: Similarity `0.75f` and NumberOfCandidates `16`.
574+
* For example, in the above query, the vector search executes with: Similarity `0.75f` and NumberOfCandidates `16`.
575575
Running this query on RavenDB's sample data returns **2** documents.
576576

577577
* However, if you increase _NumberOfCandidates_, the query will retrieve more candidate documents before applying the filtering condition.
@@ -581,8 +581,8 @@ and (vector.search(embedding.text(Name), $searchTerm))
581581
{CODE-TAB-BLOCK:sql:RQL}
582582
from "Products"
583583
where (PricePerUnit > $minPrice)
584-
// Run vector search with default similarity and NumberOfCandidates 25
585-
and (vector.search(embedding.text(Name), $searchTerm, null, 25))
584+
// Run vector search with similarity 0.75 and NumberOfCandidates 25
585+
and (vector.search(embedding.text(Name), $searchTerm, 0.75, 25))
586586
{ "minPrice" : 35.0, "searchTerm" : "italian food" }
587587
{CODE-TAB-BLOCK/}
588588
{CODE-TABS/}

Documentation/7.0/Raven.Documentation.Pages/server/configuration/indexing-configuration.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ when a static index is requested to index a complex JSON object.
556556
---
557557

558558
- **Type**: `float`
559-
- **Default**: `0.75f`
559+
- **Default**: `0f`
560560
- **Scope**: Server-wide, or per database, or per index
561561

562562
{PANEL/}

Documentation/7.0/Samples/csharp/Raven.Documentation.Samples/AiIntegration/VectorSearch/VectorSearchUsingDynamicQuery.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public async Task Examples()
3434
// Call 'ByText'
3535
// Provide the term for the similarity comparison
3636
searchTerm => searchTerm.ByText("italian food"),
37-
// Optionally, specify the minimum similarity level
37+
// It is recommended to specify the minimum similarity level
3838
0.82f,
3939
// Optionally, specify the number of candidates for the search
4040
20)
@@ -188,7 +188,7 @@ where vector.search(embedding.text(Name), $searchTerm, 0.82, 20)")
188188
// Provide the vector for the similarity comparison
189189
queryVector => queryVector.ByEmbedding(
190190
new RavenVector<float>(new float[] { 6.599999904632568f, 7.699999809265137f })),
191-
// Optionally, specify the minimum similarity level
191+
// It is recommended to specify the minimum similarity level
192192
0.85f,
193193
// Optionally, specify the number of candidates for the search
194194
10)
@@ -417,7 +417,8 @@ where exact(vector.search(embedding.text(Name), $searchTerm))")
417417
// Perform a vector search:
418418
.VectorSearch(
419419
field => field.WithText(x => x.Name),
420-
searchTerm => searchTerm.ByText("italian food"))
420+
searchTerm => searchTerm.ByText("italian food"),
421+
0.75f, 16)
421422
.Customize(x => x.WaitForNonStaleResults())
422423
.ToList();
423424
#endregion
@@ -430,7 +431,8 @@ where exact(vector.search(embedding.text(Name), $searchTerm))")
430431
.Where(x => x.PricePerUnit > 35)
431432
.VectorSearch(
432433
field => field.WithText(x => x.Name),
433-
searchTerm => searchTerm.ByText("italian food"))
434+
searchTerm => searchTerm.ByText("italian food"),
435+
0.75f, 16)
434436
.Customize(x => x.WaitForNonStaleResults())
435437
.ToListAsync();
436438
#endregion
@@ -443,7 +445,8 @@ where exact(vector.search(embedding.text(Name), $searchTerm))")
443445
.DocumentQuery<Product>()
444446
.VectorSearch(
445447
field => field.WithText(x => x.Name),
446-
searchTerm => searchTerm.ByText("italian food"))
448+
searchTerm => searchTerm.ByText("italian food"),
449+
0.75f, 16)
447450
.WhereGreaterThan(x => x.PricePerUnit, 35)
448451
.WaitForNonStaleResults()
449452
.ToList();
@@ -457,7 +460,8 @@ where exact(vector.search(embedding.text(Name), $searchTerm))")
457460
.AsyncDocumentQuery<Product>()
458461
.VectorSearch(
459462
field => field.WithText(x => x.Name),
460-
searchTerm => searchTerm.ByText("italian food"))
463+
searchTerm => searchTerm.ByText("italian food"),
464+
0.75f, 16)
461465
.WhereGreaterThan(x => x.PricePerUnit, 35)
462466
.WaitForNonStaleResults()
463467
.ToListAsync();
@@ -470,7 +474,7 @@ where exact(vector.search(embedding.text(Name), $searchTerm))")
470474
var similarProducts = session.Advanced
471475
.RawQuery<Product>(@"
472476
from 'Products'
473-
where (PricePerUnit > $minPrice) and (vector.search(embedding.text(Name), $searchTerm))")
477+
where (PricePerUnit > $minPrice) and (vector.search(embedding.text(Name), $searchTerm, 0.75, 16))")
474478
.AddParameter("minPrice", 35.0)
475479
.AddParameter("searchTerm", "italian food")
476480
.WaitForNonStaleResults()
@@ -484,7 +488,7 @@ where exact(vector.search(embedding.text(Name), $searchTerm))")
484488
var similarProducts = await asyncSession.Advanced
485489
.AsyncRawQuery<Product>(@"
486490
from 'Products'
487-
where (PricePerUnit > $minPrice) and (vector.search(embedding.text(Name), $searchTerm))")
491+
where (PricePerUnit > $minPrice) and (vector.search(embedding.text(Name), $searchTerm, 0.75, 16))")
488492
.AddParameter("minPrice", 35.0)
489493
.AddParameter("searchTerm", "italian food")
490494
.WaitForNonStaleResults()
@@ -717,7 +721,7 @@ where vector.search(embedding.f32_i1(TagsEmbeddedAsSingle), $queryVector)")
717721
// Call 'ByText'
718722
// Provide the search term for the similarity comparison
719723
searchTerm => searchTerm.ByText("candy"),
720-
// Optionally, specify the minimum similarity level
724+
// It is recommended to specify the minimum similarity level
721725
0.75f)
722726
.Customize(x => x.WaitForNonStaleResults())
723727
.ToList();

0 commit comments

Comments
 (0)