Dela via


ConfigureOptionsEmbeddingGenerator<TInput,TEmbedding> Class

Definition

A delegating embedding generator that updates or replaces the EmbeddingGenerationOptions used by the remainder of the pipeline.

generic <typename TInput, typename TEmbedding>
 where TEmbedding : Embeddingpublic ref class ConfigureOptionsEmbeddingGenerator sealed : Microsoft::Extensions::AI::DelegatingEmbeddingGenerator<TInput, TEmbedding>
public sealed class ConfigureOptionsEmbeddingGenerator<TInput,TEmbedding> : Microsoft.Extensions.AI.DelegatingEmbeddingGenerator<TInput,TEmbedding> where TEmbedding : Embedding
type ConfigureOptionsEmbeddingGenerator<'Input, 'Embedding (requires 'Embedding :> Embedding)> = class
    inherit DelegatingEmbeddingGenerator<'Input, 'Embedding (requires 'Embedding :> Embedding)>
Public NotInheritable Class ConfigureOptionsEmbeddingGenerator(Of TInput, TEmbedding)
Inherits DelegatingEmbeddingGenerator(Of TInput, TEmbedding)

Type Parameters

TInput

Specifies the type of the input passed to the generator.

TEmbedding

Specifies the type of the embedding instance produced by the generator.

Inheritance
ConfigureOptionsEmbeddingGenerator<TInput,TEmbedding>

Remarks

The configuration callback is invoked with the caller-supplied EmbeddingGenerationOptions instance. To override the caller-supplied options with a new instance, the callback may simply return that new instance, for example _ => new EmbeddingGenerationOptions() { Dimensions = 100 }. To provide a new instance only if the caller-supplied instance is null, the callback may conditionally return a new instance, for example options => options ?? new EmbeddingGenerationOptions() { Dimensions = 100 }. Any changes to the caller-provided options instance will persist on the original instance, so the callback must take care to only do so when such mutations are acceptable, such as by cloning the original instance and mutating the clone, for example: options => { var newOptions = options?.Clone() ?? new(); newOptions.Dimensions = 100; return newOptions; }

The callback may return null, in which case a null options will be passed to the next generator in the pipeline.

The provided implementation of IEmbeddingGenerator<TInput,TEmbedding> is thread-safe for concurrent use so long as the employed configuration callback is also thread-safe for concurrent requests. If callers employ a shared options instance, care should be taken in the configuration callback, as multiple calls to it may end up running in parallel with the same options instance.

Constructors

ConfigureOptionsEmbeddingGenerator<TInput,TEmbedding>(IEmbeddingGenerator<TInput, TEmbedding>, Func<EmbeddingGenerationOptions,EmbeddingGenerationOptions>)

Initializes a new instance of the ConfigureOptionsEmbeddingGenerator<TInput,TEmbedding> class with the specified configureOptions callback.

Properties

InnerGenerator

Gets the inner IEmbeddingGenerator<TInput,TEmbedding>.

(Inherited from DelegatingEmbeddingGenerator<TInput,TEmbedding>)
Metadata

Gets metadata that describes the IEmbeddingGenerator<TInput,TEmbedding>.

(Inherited from DelegatingEmbeddingGenerator<TInput,TEmbedding>)

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

(Inherited from DelegatingEmbeddingGenerator<TInput,TEmbedding>)
Dispose(Boolean)

Provides a mechanism for releasing unmanaged resources.

(Inherited from DelegatingEmbeddingGenerator<TInput,TEmbedding>)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GenerateAsync(IEnumerable<TInput>, EmbeddingGenerationOptions, CancellationToken)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetService<TService>(Object)

Asks the IEmbeddingGenerator<TInput,TEmbedding> for an object of type TService.

(Inherited from DelegatingEmbeddingGenerator<TInput,TEmbedding>)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Extension Methods

GenerateAndZipAsync<TInput,TEmbedding>(IEmbeddingGenerator<TInput,TEmbedding>, IEnumerable<TInput>, EmbeddingGenerationOptions, CancellationToken)

Generates embeddings for each of the supplied values and produces a list that pairs each input value with its resulting embedding.

GenerateEmbeddingAsync<TInput,TEmbedding>(IEmbeddingGenerator<TInput,TEmbedding>, TInput, EmbeddingGenerationOptions, CancellationToken)

Generates an embedding from the specified value.

Applies to