SemanticRoutingChatClient Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Routes requests by semantic similarity to app-provided example utterances.
public ref class SemanticRoutingChatClient sealed : Microsoft::Extensions::AI::RoutingChatClient
[System.Diagnostics.CodeAnalysis.Experimental("MEAI001", UrlFormat="https://aka.ms/dotnet-extensions-warnings/{0}")]
public sealed class SemanticRoutingChatClient : Microsoft.Extensions.AI.RoutingChatClient
[<System.Diagnostics.CodeAnalysis.Experimental("MEAI001", UrlFormat="https://aka.ms/dotnet-extensions-warnings/{0}")>]
type SemanticRoutingChatClient = class
inherit RoutingChatClient
Public NotInheritable Class SemanticRoutingChatClient
Inherits RoutingChatClient
- Inheritance
- Attributes
Remarks
Profile embeddings are generated lazily and cached. Each request embeds the last user message and selects the client with the highest score after aggregating the cosine similarities of the best-matching profile utterances. The configured default client is selected when no user message is available or when the highest score is below the configured threshold.
The configured client instances are used as stable routing identities and are distinguished by reference. Per-call options do not participate in that identity. By default this instance owns the clients and embedding generator and disposes them when it is disposed.
The example-utterance routing approach is inspired by Aurelio Labs' semantic-router project.
Constructors
| Name | Description |
|---|---|
| SemanticRoutingChatClient(IEmbeddingGenerator<String,Embedding<Single>>, IReadOnlyDictionary<IChatClient,IReadOnlyList<String>>, IChatClient, Single, Int32, SemanticRoutingChatClient+ScoreAggregation, Boolean) |
Initializes a new instance of the SemanticRoutingChatClient class. |
Methods
| Name | Description |
|---|---|
| Dispose() |
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. (Inherited from RoutingChatClient) |
| Dispose(Boolean) |
Provides a mechanism for releasing resources owned by the derived instance. (Inherited from RoutingChatClient) |
| GetResponseAsync(IEnumerable<ChatMessage>, ChatOptions, CancellationToken) |
Sends chat messages and returns the response. (Inherited from RoutingChatClient) |
| GetService(Type, Object) |
Asks the IChatClient for an object of the specified type |
| GetStreamingResponseAsync(IEnumerable<ChatMessage>, ChatOptions, CancellationToken) |
Sends chat messages and streams the response. (Inherited from RoutingChatClient) |
| SelectClientAsync(RoutingContext, CancellationToken) |
Selects the client to invoke for the request. (Inherited from RoutingChatClient) |