Dela via


EmbeddingGeneratorExtensions.GenerateEmbeddingAsync<TInput,TEmbedding> Method

Definition

Generates an embedding from the specified value.

public static System.Threading.Tasks.Task<TEmbedding> GenerateEmbeddingAsync<TInput,TEmbedding> (this Microsoft.Extensions.AI.IEmbeddingGenerator<TInput,TEmbedding> generator, TInput value, Microsoft.Extensions.AI.EmbeddingGenerationOptions? options = default, System.Threading.CancellationToken cancellationToken = default) where TEmbedding : Microsoft.Extensions.AI.Embedding;
static member GenerateEmbeddingAsync : Microsoft.Extensions.AI.IEmbeddingGenerator<'Input, 'Embedding (requires 'Embedding :> Microsoft.Extensions.AI.Embedding)> * 'Input * Microsoft.Extensions.AI.EmbeddingGenerationOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Embedding (requires 'Embedding :> Microsoft.Extensions.AI.Embedding)> (requires 'Embedding :> Microsoft.Extensions.AI.Embedding)
<Extension()>
Public Function GenerateEmbeddingAsync(Of TInput, TEmbedding) (generator As IEmbeddingGenerator(Of TInput, TEmbedding), value As TInput, Optional options As EmbeddingGenerationOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of TEmbedding)

Type Parameters

TInput

The type from which embeddings will be generated.

TEmbedding

The type of embedding to generate.

Parameters

generator
IEmbeddingGenerator<TInput,TEmbedding>

The embedding generator.

value
TInput

A value from which an embedding will be generated.

options
EmbeddingGenerationOptions

The embedding generation options to configure the request.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

Task<TEmbedding>

The generated embedding for the specified value.

Remarks

This operations is equivalent to using GenerateAsync(IEnumerable<TInput>, EmbeddingGenerationOptions, CancellationToken) with a collection composed of the single value and then returning the first embedding element from the resulting GeneratedEmbeddings<TEmbedding> collection.

Applies to