SemanticRoutingChatClient Class

Definition

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
SemanticRoutingChatClient
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 serviceType.

(Inherited from RoutingChatClient)
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)

Extension Methods

Name Description
AsBuilder(IChatClient)

Creates a new ChatClientBuilder using innerClient as its inner client.

GetRequiredService(IChatClient, Type, Object)

Asks the IChatClient for an object of the specified type serviceType and throws an exception if one isn't available.

GetRequiredService<TService>(IChatClient, Object)

Asks the IChatClient for an object of type TService and throws an exception if one isn't available.

GetResponseAsync(IChatClient, ChatMessage, ChatOptions, CancellationToken)

Sends a chat message and returns the response messages.

GetResponseAsync(IChatClient, String, ChatOptions, CancellationToken)

Sends a user chat text message and returns the response messages.

GetResponseAsync<T>(IChatClient, ChatMessage, ChatOptions, Nullable<Boolean>, CancellationToken)

Sends a chat message, requesting a response matching the type T.

GetResponseAsync<T>(IChatClient, ChatMessage, JsonSerializerOptions, ChatOptions, Nullable<Boolean>, CancellationToken)

Sends a chat message, requesting a response matching the type T.

GetResponseAsync<T>(IChatClient, IEnumerable<ChatMessage>, ChatOptions, Nullable<Boolean>, CancellationToken)

Sends chat messages, requesting a response matching the type T.

GetResponseAsync<T>(IChatClient, IEnumerable<ChatMessage>, JsonSerializerOptions, ChatOptions, Nullable<Boolean>, CancellationToken)

Sends chat messages, requesting a response matching the type T.

GetResponseAsync<T>(IChatClient, String, ChatOptions, Nullable<Boolean>, CancellationToken)

Sends a user chat text message, requesting a response matching the type T.

GetResponseAsync<T>(IChatClient, String, JsonSerializerOptions, ChatOptions, Nullable<Boolean>, CancellationToken)

Sends a user chat text message, requesting a response matching the type T.

GetService<TService>(IChatClient, Object)

Asks the IChatClient for an object of type TService.

GetStreamingResponseAsync(IChatClient, ChatMessage, ChatOptions, CancellationToken)

Sends a chat message and streams the response messages.

GetStreamingResponseAsync(IChatClient, String, ChatOptions, CancellationToken)

Sends a user chat text message and streams the response messages.

Applies to