TextEmbeddingsModule
TypeScript API implementation of the useTextEmbeddings hook.
API Reference
- For detailed API Reference for
TextEmbeddingsModulesee:TextEmbeddingsModuleAPI Reference. - For all text embeddings models available out-of-the-box in React Native ExecuTorch see: Text Embeddings Models.
High Level Overview
import {
TextEmbeddingsModule,
ALL_MINILM_L6_V2,
} from 'react-native-executorch';
// Creating an instance
const textEmbeddingsModule = new TextEmbeddingsModule();
// Loading the model
await textEmbeddingsModule.load(ALL_MINILM_L6_V2);
// Running the model
const embedding = await textEmbeddingsModule.forward('Hello World!');
Methods
All methods of TextEmbeddingsModule are explained in details here: TextEmbeddingsModule API Reference
Loading the model
To load the model, use the load method. It accepts an object:
-
model- Object containing:modelSource- Location of the used model.tokenizerSource- Location of the used tokenizer.
-
onDownloadProgressCallback- Callback to track download progress.
This method returns a promise, which can resolve to an error or void.
For more information on loading resources, take a look at loading models page.
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.