Skip to main content

TextEmbeddingsModule

TypeScript API implementation of the useTextEmbeddings hook.

Reference

import {
TextEmbeddingsModule,
ALL_MINILM_L6_V2,
All_MINILM_L6_V2_TOKENIZER,
} from 'react-native-executorch';

// Loading the model
await TextEmbeddingsModule.load(ALL_MINILM_L6_V2, All_MINILM_L6_V2_TOKENIZER);

// Running the model
const embedding = await TextEmbeddingsModule.forward('Hello World!');

Methods

MethodTypeDescription
load(modelSource: ResourceSource, tokenizerSource: ResourceSource): Promise<void>Loads the model, where modelSource is a string that specifies the location of the model binary and tokenizerSource is a string that specifies the location of the tokenizer JSON file.
forward(input: string): Promise<number[]>Executes the model's forward pass, where input is a text that will be embedded.
onDownloadProgress(callback: (downloadProgress: number) => void): anySubscribe to the download progress event.

Type definitions

type ResourceSource = string | number | object;

Loading the model

To load the model, use the load method. It accepts the modelSource which is a string that specifies the location of the model binary and tokenizerSource which is a string that specifies the location of the tokenizer JSON file. For more information, take a look at loading models page. This method returns a promise, which can resolve to an error or void.

Running the model

To run the model, you can use the forward method. It accepts one argument, which is the text you want to embed. The method returns a promise, which can resolve either to an error or an array of numbers representing the embedding.