EmbeddingModelBase<T>
Base Classes · AiDotNet.RetrievalAugmentedGeneration.Embeddings
Provides a base implementation for embedding models with common functionality.
Implements: IDisposable, IEmbeddingModel<T>
Known derived types: CohereEmbeddingModel<T>, GooglePalmEmbeddingModel<T>, HuggingFaceEmbeddingModel<T>, LocalTransformerEmbedding<T>, MultiModalEmbeddingModel<T>, ONNXSentenceTransformer<T>, OpenAIEmbeddingModel<T>, SentenceTransformersFineTuner<T>, StaticWordEmbeddingModel<T>, StubEmbeddingModel<T>, VoyageAIEmbeddingModel<T>
For Beginners
This is the foundation that all embedding models build upon.
Think of it like a template for creating embedding models:
- It handles common tasks (checking inputs, batching text, normalizing vectors)
- Specific embedding models (BERT, GPT, etc.) just fill in how they convert text to numbers
- This keeps code consistent and reduces duplication
How It Works
This abstract class implements the IEmbeddingModel interface and provides common functionality for text embedding models. It handles validation, batching, and normalization while allowing derived classes to focus on implementing the core embedding algorithm.
Properties
| Property | Summary |
|---|---|
int EmbeddingDimension { get; } |
Gets the dimensionality of the embedding vectors produced by this model. |
int MaxTokens { get; } |
Gets the maximum length of text (in tokens) that this model can process. |
Methods
| Method | Summary |
|---|---|
Matrix<T> EmbedBatch(IEnumerable<string> texts) |
Embeds multiple text strings into vector representations in a single batch operation. |
Task<Matrix<T>> EmbedBatchAsync(IEnumerable<string> texts) |
Asynchronously embeds multiple text strings into vector representations in a single batch operation. |
Task<Vector<T>> EmbedAsync(string text) |
Asynchronously embeds a single text string into a vector representation. |
Vector<T> Embed(string text) |
Embeds a single text string into a vector representation. |
void Dispose() |
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. |