Skip to main content
Version: 0.10.0-legacy

TextEmbeddingsModule

TypeScript API implementation of the useTextEmbeddings hook.

API Reference​

High Level Overview​

import { models, TextEmbeddingsModule } from 'react-native-executorch/legacy';
// Creating an instance and loading the model
const textEmbeddingsModule = await TextEmbeddingsModule.fromModelName(
models.text_embedding.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​

Use the static fromModelName factory method. It accepts a model config object (e.g. ALL_MINILM_L6_V2) containing:

And an optional onDownloadProgress callback. It returns a promise resolving to a TextEmbeddingsModule instance.

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.