Method GetEmbeddingsAsync
- Namespace
- LMKit.Embeddings
- Assembly
- LM-Kit.NET.dll
GetEmbeddingsAsync(Attachment, CancellationToken)
Asynchronously generates the embedding vector for a given file attachment. If the associated LM supports image embeddings, image attachments (for example, PNG, JPEG, TIFF) will be processed into embeddings; otherwise, text‑based attachments (for example, TXT, HTML) will be used.
public Task<float[]> GetEmbeddingsAsync(Attachment attachment, CancellationToken cancellationToken = default)
Parameters
attachment
AttachmentThe file attachment containing content, name, MIME type, and size. Supported formats include: PNG, BMP, GIF, PSD, PIC, JPEG, PNM, HDR, TGA, WEBP, TIFF, TXT, HTML.
cancellationToken
CancellationTokenOptional. A CancellationToken for handling cancellation requests.
Returns
- Task<float[]>
A task that represents the asynchronous operation. The task result contains an array of floats representing the embedding vector of the attachment’s content.
Exceptions
- ArgumentNullException
Thrown when
attachment
isnull
.- InvalidModelException
Thrown when
attachment
requires vision processing but the current model does not support image embeddings.
GetEmbeddingsAsync(string, CancellationToken)
Asynchronously generates the embedding vector for a given text string. This vector represents the text in a high-dimensional space, enabling various natural language processing tasks by capturing semantic meaning.
public Task<float[]> GetEmbeddingsAsync(string text, CancellationToken cancellationToken = default)
Parameters
text
stringThe text string to be converted into an embedding vector. Cannot be null or empty.
cancellationToken
CancellationTokenOptional. A CancellationToken for handling cancellation requests.
Returns
- Task<float[]>
A task that represents the asynchronous operation. The task result contains an array of floats representing the embedding vector of the input text.
Remarks
The dimension of the array is specified by the EmbeddingSize property.
Exceptions
- ArgumentNullException
Thrown when the input text is null or empty.
GetEmbeddingsAsync(IEnumerable<string>, CancellationToken)
Asynchronously generates embedding vectors for a collection of text strings. Each vector represents a text in a high-dimensional space, enabling various natural language processing tasks by capturing semantic meaning.
public Task<float[][]> GetEmbeddingsAsync(IEnumerable<string> text, CancellationToken cancellationToken = default)
Parameters
text
IEnumerable<string>An enumerable of text strings to be converted into embedding vectors. Cannot be null or empty.
cancellationToken
CancellationTokenOptional. A CancellationToken for handling cancellation requests.
Returns
- Task<float[][]>
A task that represents the asynchronous operation. The task result contains an array of float arrays, each representing the embedding vector of the corresponding input text.
Exceptions
- ArgumentNullException
Thrown when the input text is null or empty.
GetEmbeddingsAsync(IList<int>, CancellationToken)
Asynchronously generates the embedding vector for a given tokenized text. This vector represents the text in a high-dimensional space, enabling various natural language processing tasks by capturing semantic meaning.
public Task<float[]> GetEmbeddingsAsync(IList<int> tokens, CancellationToken cancellationToken = default)
Parameters
tokens
IList<int>The list of tokens to be converted into an embedding vector. Cannot be null or empty.
cancellationToken
CancellationTokenOptional. A CancellationToken for handling cancellation requests.
Returns
- Task<float[]>
A task that represents the asynchronous operation. The task result contains an array of floats representing the embedding vector of the input tokens.
Remarks
The dimension of the array is specified by the EmbeddingSize property.
Exceptions
- ArgumentNullException
Thrown when the input tokens are null or empty.
GetEmbeddingsAsync(IEnumerable<IList<int>>, CancellationToken)
Asynchronously generates embedding vectors for a collection of tokenized texts. Each vector represents a text in a high-dimensional space, enabling various natural language processing tasks by capturing semantic meaning.
public Task<float[][]> GetEmbeddingsAsync(IEnumerable<IList<int>> tokens, CancellationToken cancellationToken = default)
Parameters
tokens
IEnumerable<IList<int>>An enumerable of token lists to be converted into embedding vectors. Cannot be null or empty.
cancellationToken
CancellationTokenOptional. A CancellationToken for handling cancellation requests.
Returns
- Task<float[][]>
A task that represents the asynchronous operation. The task result contains an array of float arrays, each representing the embedding vector of the corresponding input tokens.
Exceptions
- ArgumentNullException
Thrown when the input tokens are null or empty.