Performs embedding extraction on text.
Signature:
export declare class TextEmbedder extends TaskRunner
Extends: TaskRunner
Methods
Method | Modifiers | Description |
---|---|---|
cosineSimilarity(u, v) | static |
Utility function to compute cosine similarity[1] between two Embedding objects.[1]: https://en.wikipedia.org/wiki/Cosine_similarity |
createFromModelBuffer(wasmFileset, modelAssetBuffer) | static |
Initializes the Wasm runtime and creates a new text embedder based on the provided model asset buffer. |
createFromModelPath(wasmFileset, modelAssetPath) | static |
Initializes the Wasm runtime and creates a new text embedder based on the path to the model asset. |
createFromOptions(wasmFileset, textEmbedderOptions) | static |
Initializes the Wasm runtime and creates a new text embedder from the provided options. |
embed(text) | Performs embeding extraction on the provided text and waits synchronously for the response. | |
setOptions(options) | Sets new options for the text embedder.Calling setOptions() with a subset of options only affects those options. You can reset an option back to its default value by explicitly setting it to undefined . |
TextEmbedder.cosineSimilarity()
Utility function to compute cosine similarity[1] between two Embedding
objects.
[1]: https://en.wikipedia.org/wiki/Cosine_similarity
Signature:
static cosineSimilarity(u: Embedding, v: Embedding): number;
Parameters
Parameter | Type | Description |
---|---|---|
u | Embedding | |
v | Embedding |
Returns:
number
Exceptions
if the embeddings are of different types(float vs. quantized), have different sizes, or have an L2-norm of 0.
TextEmbedder.createFromModelBuffer()
Initializes the Wasm runtime and creates a new text embedder based on the provided model asset buffer.
Signature: