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
- 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
adapterIPlatformAdapterThe platform adapter to use for API calls.
modelNamestringThe 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
apiKeystringThe API key for authenticating with Google AI.
modelNamestringThe 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
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
valuesIEnumerable<string>The sequence of values for which to generate embeddings.
optionsEmbeddingGenerationOptionsThe embedding generation options with which to configure the request.
cancellationTokenCancellationTokenThe CancellationToken to monitor for cancellation requests. The default is None.
Returns
Exceptions
- ArgumentNullException
valuesis 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
serviceTypeTypeThe type of object being requested.
serviceKeyobjectAn optional key that can be used to help identify the target service.
Returns
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
serviceTypeis null.