Back to Devexpress

SemanticSearchBehavior Class

windowsforms-devexpress-dot-aiintegration-dot-winforms-8ee88594.md

latest3.8 KB
Original Source

SemanticSearchBehavior Class

Enables AI-driven semantic search in GridControl, GridLookUpEdit, and SearchLookUpEdit controls.

Namespace : DevExpress.AIIntegration.WinForms

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

NuGet Package : DevExpress.AIIntegration.WinForms.SemanticSearch

Declaration

csharp
public sealed class SemanticSearchBehavior :
    BehaviorWithEvents<ISemanticSearchBehaviorSource>,
    ISemanticSearchCaller
vb
Public NotInheritable Class SemanticSearchBehavior
    Inherits BehaviorWithEvents(Of ISemanticSearchBehaviorSource)
    Implements ISemanticSearchCaller

Remarks

Warning

This help topic describes v25.1.3 (RTM), which includes the updated and improved semantic search API. If you are using the BETA version (v25.1.2), the API differs. See our demo project for details on how to activate and configure semantic search in BETA.

Run Demo: Semantic Search (BETA)

  1. Drop the BehaviorManager component from the Toolbox onto a Form.
  2. Add a SemanticSearchBehavior and attach it to a DevExpress UI control (GridControl, GridLookUpEdit, or SearchLookUpEdit).
  3. Configure behavior settings:

The following code snippet activates semantic search for a GridLookUpEdit:

csharp
public Form1() {
    InitializeComponent();
    gridLookUpEdit1.Properties.DataSource = DataHelper.Items;
    gridLookUpEdit1.Properties.DisplayMember = "Model";
    gridLookUpEdit1.Properties.ValueMember = "Id";

    behaviorManager1.Attach<SemanticSearchBehavior>(gridLookUpEdit1.Properties.View, behavior => {
        behavior.Properties.VectorCollectionName = "Cars";
        behavior.Properties.DataSourceKeyField = "Id";
        behavior.Properties.SearchResultCount = 10;
        behavior.Properties.SearchMode = ControlSearchMode.Semantic;
        // It is implied, that Cosine Distance filtering is used for the vector store.
        // Lower = more similar
        behavior.Properties.ScoreThreshold = 0.5D;
        behavior.Properties.ScoreThresholdFilter = ScoreThresholdFilter.LessOrEqual;
    });
}

Note

Call the BehaviorInitializer.Initialize() method at application startup if your project targets the .NET Framework and you create AI-powered behaviors in code. Otherwise, an exception is thrown.

csharp
internal static class Program {
    [STAThread]
    static void Main() {
        //...
        // The Initialize() method forcibly initializes the behavior manager in .NET Framework apps.
        DevExpress.AIIntegration.WinForms.BehaviorInitializer.Initialize();
        Application.Run(new Form1());
    }
}

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

Inheritance

Object DevExpress.Utils.MVVM.BehaviorBase DevExpress.Utils.Behaviors.Behavior DevExpress.Utils.Behaviors.Behavior<DevExpress.AIIntegration.WinForms.ISemanticSearchBehaviorSource> DevExpress.Utils.Behaviors.BehaviorWithEvents<DevExpress.AIIntegration.WinForms.ISemanticSearchBehaviorSource> SemanticSearchBehavior

See Also

Semantic Search

SemanticSearchBehavior Members

DevExpress.AIIntegration.WinForms Namespace