Table of Contents

Class GenerativeAIEmbeddingGenerator

Namespace
GenerativeAI.Microsoft
Assembly
GenerativeAI.Microsoft.dll

Provides embedding generation capabilities using Google's Generative AI models through the Microsoft.Extensions.AI abstraction.

public sealed class GenerativeAIEmbeddingGenerator : IEmbeddingGenerator<string, Embedding<float>>, IEmbeddingGenerator, IDisposable
Inheritance
GenerativeAIEmbeddingGenerator
Implements
IEmbeddingGenerator<string, Embedding<float>>
IEmbeddingGenerator
Inherited Members
Extension Methods

Constructors

GenerativeAIEmbeddingGenerator(IPlatformAdapter, string)

Initializes a new instance of the GenerativeAIEmbeddingGenerator class.

public GenerativeAIEmbeddingGenerator(IPlatformAdapter adapter, string modelName = "models/gemini-embedding-001")

Parameters

adapter IPlatformAdapter

The platform adapter to use for API calls.

modelName string

The name of the embedding model to use. Defaults to "models/gemini-embedding-001".

GenerativeAIEmbeddingGenerator(string, string)

Initializes a new instance of the GenerativeAIEmbeddingGenerator class.

public GenerativeAIEmbeddingGenerator(string apiKey, string modelName = "models/gemini-embedding-001")

Parameters

apiKey string

The API key for authenticating with Google AI.

modelName string

The name of the embedding model to use. Defaults to "models/gemini-embedding-001".

Properties

Metadata

public EmbeddingGeneratorMetadata Metadata { get; }

Property Value

EmbeddingGeneratorMetadata

Model

Gets the underlying EmbeddingModel instance.

public EmbeddingModel Model { get; }

Property Value

EmbeddingModel

Methods

Dispose()

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

public void Dispose()

GenerateAsync(IEnumerable<string>, EmbeddingGenerationOptions?, CancellationToken)

Generates embeddings for each of the supplied values.

public Task<GeneratedEmbeddings<Embedding<float>>> GenerateAsync(IEnumerable<string> values, EmbeddingGenerationOptions? options = null, CancellationToken cancellationToken = default)

Parameters

values IEnumerable<string>

The sequence of values for which to generate embeddings.

options EmbeddingGenerationOptions

The embedding generation options with which to configure the request.

cancellationToken CancellationToken

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

Returns

Task<GeneratedEmbeddings<Embedding<float>>>

The generated embeddings.

Exceptions

ArgumentNullException

values is null.

GetService(Type, object?)

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

public object? GetService(Type serviceType, object? serviceKey = null)

Parameters

serviceType Type

The type of object being requested.

serviceKey object

An optional key that can be used to help identify the target service.

Returns

object

The found object, otherwise null.

Remarks

The purpose of this method is to allow for the retrieval of strongly typed services that might be provided by the Microsoft.Extensions.AI.IEmbeddingGenerator<TInput, TEmbedding>, including itself or any services it might be wrapping. For example, to access the Microsoft.Extensions.AI.EmbeddingGeneratorMetadata for the instance, GetService(Type, object) may be used to request it.

Exceptions

ArgumentNullException

serviceType is null.