DistributedCachingEmbeddingGenerator<TInput,TEmbedding> Class

Definition

Represents a delegating embedding generator that caches the results of embedding generation calls, storing them as JSON in an IDistributedCache.

C#
public class DistributedCachingEmbeddingGenerator<TInput,TEmbedding> : Microsoft.Extensions.AI.CachingEmbeddingGenerator<TInput,TEmbedding> where TEmbedding : Embedding

Type Parameters

TInput

The type from which embeddings will be generated.

TEmbedding

The type of embeddings to generate.

Inheritance

Remarks

The provided implementation of IEmbeddingGenerator<TInput,TEmbedding> is thread-safe for concurrent use so long as the employed IDistributedCache is similarly thread-safe for concurrent use.

Constructors

Properties

InnerGenerator

Gets the inner IEmbeddingGenerator<TInput,TEmbedding>.

(Inherited from DelegatingEmbeddingGenerator<TInput,TEmbedding>)
JsonSerializerOptions

Gets or sets JSON serialization options to use when serializing cache data.

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>)
GenerateAsync(IEnumerable<TInput>, EmbeddingGenerationOptions, CancellationToken) (Inherited from CachingEmbeddingGenerator<TInput,TEmbedding>)
GetCacheKey(ReadOnlySpan<Object>)

Computes a cache key for the specified values.

GetService(Type, Object)

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

(Inherited from DelegatingEmbeddingGenerator<TInput,TEmbedding>)
ReadCacheAsync(String, CancellationToken)

Returns a previously cached Embedding<T>, if available.

WriteCacheAsync(String, TEmbedding, CancellationToken)

Stores a TEmbedding in the underlying cache.

Extension Methods

Applies to

Toode Versioonid
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)