Skip to main content
Version: 0.9.x

TextEmbeddingsModule

TypeScript API implementation of the useTextEmbeddings hook.

API Reference​

High Level Overview​

import { models, TextEmbeddingsModule } from 'react-native-executorch';
// 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:

  • modelName - Unique name identifying the model.
  • modelSource - Location of the used model.
  • tokenizerSource - Location of the used tokenizer.
  • prompts (optional) - Asymmetric query/document prompts the model is trained with. When present, forward requires a role and prepends the matching prompt.
  • multiVector (optional) - When true, forward returns the per-token EmbeddingResult instead of a single pooled Float32Array.
  • skipListIds (optional) - Token ids to exclude from late-interaction (MaxSim) scoring.

And an optional onDownloadProgress callback (receiving a value between 0 and 1). 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, use the forward method. It accepts the text to embed and, for models with asymmetric prompts, an optional role ('query' | 'document'). The method returns a promise resolving to:

  • a Float32Array — a single pooled vector — for standard models, or
  • an EmbeddingResult with the per-token vectors for multiVector models.