windowsforms-405154-ai-powered-extensions-smart-search.md
Smart Search works alongside traditional search algorithms to offer a more powerful and user-friendly search experience. It offers results that are more aligned with what the user is seeking, even if the input contains misspellings.
When the user pauses typing in the search field within the Ribbon or Accordion control, the control sends the current search query to an AI service that understands context, synonyms, and user intent beyond exact keyword matches. Once the AI service returns its results, the control filters items accordingly.
Play the following animation to see how AI-powered smart search works in the DevExpress WinForms Ribbon control:
DevExpress.AIIntegration.WinFormsDevExpress.Win.Design (enables design-time features for DevExpress UI controls)Read the following help topics for information on how to obtain the DevExpress NuGet Feed and install DevExpress NuGet packages:
See the following help topic for information on required NuGet packages and system requirements: Register an AI Client.
The following code snippet registers the Azure OpenAI client:
using Microsoft.Extensions.AI;
using DevExpress.AIIntegration;
internal static class Program {
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
IChatClient azureChatClient = new Azure.AI.OpenAI.AzureOpenAIClient(new Uri(AzureOpenAIEndpoint),
new System.ClientModel.ApiKeyCredential(AzureOpenAIKey))
.GetChatClient(ModelId).AsIChatClient();
AIExtensionsContainerDesktop.Default.RegisterChatClient(azureChatClient);
// Uncomment the following line if your project targets the .NET Framework and
// you create AI-powered behaviors in code.
// DevExpress.AIIntegration.WinForms.BehaviorInitializer.Initialize();
Application.Run(new Form1());
}
static string AzureOpenAIEndpoint { get { return Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT"); } }
static string AzureOpenAIKey { get { return Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY"); } }
static string ModelId { get { return "MODEL_NAME"; } }
}
Imports Microsoft.Extensions.AI
Imports DevExpress.AIIntegration
Friend Module Program
<STAThread>
Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
' Register Azure.OpenAI
Dim azureChatClient As IChatClient = New Azure.AI.OpenAI.AzureOpenAIClient(New Uri(AzureOpenAIEndpoint),
New System.ClientModel.ApiKeyCredential(AzureOpenAIKey)).
GetChatClient(ModelId).AsIChatClient()
AIExtensionsContainerDesktop.Default.RegisterChatClient(azureChatClient)
' Uncomment the following line if your project targets the .NET Framework and
' you create AI-powered behaviors in code.
' DevExpress.AIIntegration.WinForms.BehaviorInitializer.Initialize()
Application.Run(New Form1())
End Sub
Private ReadOnly Property AzureOpenAIEndpoint() As String
Get
Return Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")
End Get
End Property
Private ReadOnly Property AzureOpenAIKey() As String
Get
Return Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY")
End Get
End Property
Private ReadOnly Property ModelId As String
Get
Return "MODEL_NAME"
End Get
End Property
End Module
BehaviorManager component from the Toolbox onto a Form. The Form should contain the DevExpress Ribbon and/or Accordion.Tip
Use SmartSearchRequest to manually initiate a Smart Search request:
var response = await defaultAIExtensionsContainer.SmartSearchAsync(
new SmartSearchRequest(searchQuery, new List<SmartSearchRequest.ItemInfo>() {
new SmartSearchRequest.ItemInfo("item1", "chair"),
new SmartSearchRequest.ItemInfo("item2", "sofa"),
new SmartSearchRequest.ItemInfo("item3", "knife"),
new SmartSearchRequest.ItemInfo("item4", "clock"),
new SmartSearchRequest.ItemInfo("item5", "bed"),
})
);
Once you attach the SmartSearchBehavior to a control, you should describe items so that Smart Search can find appropriate items. In the context of Smart Search, an item refers to a BarItem when working with a RibbonControl, or an AccordionControlElement when working with an AccordionControl.
Note
Item descriptions are optional if an item’s text or caption is specified (for example, a bar item’s Caption property or accordion UI element’s Text property is set to a non-empty string). Although Smart Search attempts to find items based on their text/caption, we recommend that you also describe items for improved accuracy.
Use the SmartSearchBehavior.Properties.ItemDescriptions collection property to add descriptions (AIItemDescription) for certain items. Each AIItemDescription object in the collection has two properties:
AIItemDescription.Item: An item (BarItem or AccordionControlElement).AIItemDescription.Description: A string that describes the item.If you want to exclude a specific item from Smart Search, you can add this item to the SmartSearchBehavior.Properties.ExcludedItems collection. This allows you to exclude Ribbon commands (items) or Accordion UI elements from being affected by Smart Search.
BarItemVisibility.Always or BarItemVisibility.OnlyInRuntime.See Also
DevExpress AI-powered Extensions for WinForms