Back to Devexpress

SemanticSearchBehaviorProperties.ScoreThresholdFilter Property

windowsforms-devexpress-dot-aiintegration-dot-winforms-dot-semanticsearchbehaviorproperties-2a941c34.md

latest5.1 KB
Original Source

SemanticSearchBehaviorProperties.ScoreThresholdFilter Property

Controls how the ScoreThreshold is applied during filtering.

Namespace : DevExpress.AIIntegration.WinForms

Assembly : DevExpress.AIIntegration.WinForms.SemanticSearch.v25.2.dll

NuGet Package : DevExpress.AIIntegration.WinForms.SemanticSearch

Declaration

csharp
[DefaultValue(ScoreThresholdFilter.None)]
public ScoreThresholdFilter ScoreThresholdFilter { get; set; }
vb
<DefaultValue(ScoreThresholdFilter.None)>
Public Property ScoreThresholdFilter As ScoreThresholdFilter

Property Value

TypeDefaultDescription
DevExpress.AIIntegration.SemanticSearch.ScoreThresholdFilterNone

A value that controls how the ScoreThreshold is applied during filtering.

|

Remarks

In your vectorized data model, you must annotate a vector field with the VectorStoreVector attribute and specify the desired similarity metric using the DistanceFunction property:

csharp
using Microsoft.Extensions.VectorData;

// Define a record stored in the vector store for semantic search.
public class VectorStoreRecord {
    // A unique identifier for the record in a vector store.
    [VectorStoreKey]
    public string Key { get; set; }

    // Azure OpenAI (embedding model) produces 1536-dimensional vectors.
    // Specify how vector data is stored and compared in a vector store.
    // This example uses cosine similarity as the distance function for comparisons.
    [VectorStoreVector(1536, DistanceFunction = DistanceFunction.CosineDistance)]
    public string Vector { get; set; }
}

Warning

The VectorStoreVector attribute indicates the preferred distance function, but the vector store ultimately determines which similarity metric is supported. If your vector store does not support the specified function, it will throw a runtime error.

Use the following properties to configure similarity filtering:

Score Threshold

The SemanticSearchBehavior.Properties.ScoreThreshold property specifies the minimum or maximum score at which search results are considered relevant. The actual meaning of the score depends on the selected similarity metric/distance function. For example:

Cosine Similarity

ValueDescription
1.0Vectors are identical (maximum similarity)
0.0Vectors are orthogonal (no similarity)
-1.0Vectors are opposite

Cosine Distance

ValueDescription
0.0Vectors are identical (maximum similarity)
1.0Vectors are orthogonal (no similarity)
2.0Vectors are opposite

Score Threshold Filter

The SemanticSearchBehavior.Properties.ScoreThresholdFilter property specifies how the ScoreThreshold is applied during filtering:

ValueDescription
NoneNo filtering is applied. All results are returned regardless of score.
GreaterOrEqualInclude results with a score greater than or equal to ScoreThreshold. Used with Cosine Similarity , where higher scores mean greater similarity.
LessOrEqualInclude results with a score less than or equal to ScoreThreshold. Used with Cosine Distance , where lower scores mean greater similarity.

Examples

Cosine Similarity Filtering

Returns results with similarity scores from 0.5 to 1.0:

csharp
// Higher = more similar
semanticSearchBehavior.ScoreThreshold = 0.5;
semanticSearchBehavior.ScoreThresholdFilter = ScoreThresholdFilter.GreaterOrEqual;

Cosine Distance Filtering

Returns results with distance scores from 0.0 to 0.5:

csharp
// Lower = more similar
semanticSearchBehavior.ScoreThreshold = 0.5;
semanticSearchBehavior.ScoreThresholdFilter = ScoreThresholdFilter.LessOrEqual;

See the following help topic for additional information: Semantic Search.

See Also

ScoreThreshold

SemanticSearchBehaviorProperties Class

SemanticSearchBehaviorProperties Members

DevExpress.AIIntegration.WinForms Namespace