npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@react-native-rag/executorch

v0.11.0

Published

React Native ExecuTorch wrapper for React Native RAG

Downloads

682

Readme

@react-native-rag/executorch

This package provides implementations for the Embeddings and LLM interfaces from react-native-rag, using react-native-executorch to run AI models on-device. This enables you to perform inference directly on the user's device, ensuring privacy and offline capabilities.

Installation

npm install @react-native-rag/executorch react-native-executorch react-native-worklets react-native-blob-util

react-native-worklets and react-native-blob-util are peer dependencies of react-native-executorch 0.11 and of this package (react-native-blob-util 0.24.11+). On Expo SDK 55 and 56 install react-native-worklets with your package manager rather than npx expo install, which would pick an older bundled version.

[!IMPORTANT] Babel plugin. This package ships worklets, so your app must compile them. Expo's babel-preset-expo does it automatically once react-native-worklets is installed. In a bare React Native app add 'react-native-worklets/plugin' as the last entry of plugins in babel.config.js, then restart Metro with --reset-cache. Without it generate() fails at runtime.

Requirements inherited from react-native-executorch 0.11:

  • React Native 0.83+ (bare) or Expo SDK 55+ with development builds. Expo Go is not supported. The upper bound comes from react-native-worklets: 0.10.x and 0.11.x support React Native 0.83 to 0.86, 0.12.x up to 0.87, 0.13.x 0.86 to 0.88.
  • The New Architecture enabled.
  • iOS 17.0+ and Android 13+ (minSdkVersion 26+).
  • Optional: @kesha-antonov/react-native-background-downloader (4.4.0+) keeps model downloads running in the background on iOS and Android. Without it downloads pause while the app is suspended.

With Expo, set the iOS deployment target and the Android minSdkVersion through expo-build-properties (Expo defaults to minSdkVersion 24):

{
  "expo": {
    "plugins": [
      [
        "expo-build-properties",
        { "ios": { "deploymentTarget": "17.0" }, "android": { "minSdkVersion": 26 } }
      ]
    ]
  }
}

Models are downloaded on first load() and cached on the device. No initExecutorch call or resource fetcher package is needed anymore.

Usage

ExecuTorchEmbeddings

This class allows you to use an ExecuTorch-compatible model to generate text embeddings.

import { models } from 'react-native-executorch';
import { ExecuTorchEmbeddings } from '@react-native-rag/executorch';

const embeddings = new ExecuTorchEmbeddings(
  models.textEmbeddings.ALL_MINILM_L6_V2.DEFAULT
);

Parameters:

| Name | Type | Description | | -------------------- | ---------------------------- | --------------------------------------------------------------- | | modelPath | string | URL or local path of the embedding model (.pte). | | tokenizerPath | string | URL or local path of the tokenizer (tokenizer.json). | | defaultPrompt | string (optional) | Prompt prepended to inputs that have no more specific prompt below. Registry models may carry one. | | documentPrompt | string (optional) | Prompt prepended to documents being indexed. Falls back to defaultPrompt; '' prepends nothing. | | queryPrompt | string (optional) | Prompt prepended to search queries. Falls back to defaultPrompt; '' prepends nothing. | | onDownloadProgress | (progress: number) => void | Download progress callback in the 0-1 range. |

Vector stores call embed(text, { kind }) with 'document' when indexing and 'query' when searching, so asymmetric models that expect different prefixes on each side can be configured with documentPrompt and queryPrompt:

const embeddings = new ExecuTorchEmbeddings({
  ...models.textEmbeddings.LFM2_5_EMBEDDING_350M.DEFAULT, // ships `defaultPrompt: 'query: '`
  documentPrompt: 'document: ',
});

ExecuTorchLLM

This class allows you to use an ExecuTorch-compatible language model for text generation.

import { models } from 'react-native-executorch';
import { ExecuTorchLLM } from '@react-native-rag/executorch';

const llm = new ExecuTorchLLM({
  ...models.llm.LFM2_5_1_2B.DEFAULT,
  generationConfig: { temperature: 0.7, maxNewTokens: 512 },
});

Parameters:

| Name | Type | Description | | --------------------- | ---------------------------- | --------------------------------------------------------------------------- | | modelPath | string | URL or local path of the LLM (.pte). | | tokenizerPath | string | URL or local path of the tokenizer (tokenizer.json). | | tokenizerConfigPath | string | URL or local path of the tokenizer config (tokenizer_config.json). | | generationConfig | LLMGenerationConfig | temperature, maxNewTokens, ignoreEos. See react-native-executorch. | | systemPrompt | string (optional) | Prepended when the history has no system message. Defaults to DEFAULT_SYSTEM_PROMPT; pass '' to disable. | | onDownloadProgress | (progress: number) => void | Download progress callback in the 0-1 range. |

Each generate() call is stateless: the whole message history is rendered through the model's chat template and fed to the model from a fresh KV cache. The model itself is loaded once by load() and kept in memory until unload(). One instance runs one generation at a time; a generate() call that overlaps a running one rejects, so call interrupt() and wait for the pending promise first.

When the history does not fit the model's context window, the oldest turns are dropped until the prompt leaves room for the response (generationConfig.maxNewTokens, or 512 tokens when unset). System messages and the last message are always kept.

Choosing a backend

models.*.DEFAULT resolves at import time to the best backend linked into your app: Core ML or MLX on iOS devices, Vulkan on Android devices, XNNPACK on the iOS simulator and as the universal fallback. You can pin a variant explicitly, for example models.textEmbeddings.ALL_MINILM_L6_V2.XNNPACK_FP32.

To limit the native binaries downloaded at install time, add a react-native-executorch block to your app's package.json:

{
  "react-native-executorch": {
    "features": ["llm", "textEmbeddings"]
  }
}

Integration with react-native-rag

You can use these classes directly with the useRAG hook:

import { useRAG } from 'react-native-rag';
import { ExecuTorchLLM, ExecuTorchEmbeddings } from '@react-native-rag/executorch';
import { MemoryVectorStore } from 'react-native-rag';

const App = () => {
  const { isReady, generate } = useRAG({
    llm,
    vectorStore: new MemoryVectorStore({ embeddings }),
  });

  // ... your component logic
};

Migrating from 0.10

  • Requires react-native-executorch ^0.11.0 and react-native-blob-util 0.24.11+. The adapter API is unchanged.

Migrating from 0.9

  • Install react-native-worklets and react-native-blob-util. Remove react-native-executorch-expo-resource-fetcher (or the bare fetcher) and the initExecutorch(...) call.
  • Model registry accessors changed in react-native-executorch: models.text_embedding.all_minilm_l6_v2() is now models.textEmbeddings.ALL_MINILM_L6_V2.DEFAULT, and models.llm.qwen3_0_6b() is now models.llm.QWEN3_0_6B.DEFAULT.
  • Constructor fields follow the new registry shape: modelSource, tokenizerSource and tokenizerConfigSource are now modelPath, tokenizerPath and tokenizerConfigPath, and only accept strings (URLs or local paths).
  • chatConfig on ExecuTorchLLM is now generationConfig with the react-native-executorch LLMGenerationConfig shape. chatConfig.systemPrompt is now the top-level systemPrompt parameter (a system message in the history takes precedence). chatConfig.contextStrategy is gone: the oldest turns are dropped automatically when the history does not fit the context window.
  • The responseCallback and messageHistoryCallback parameters were removed. They were never wired up. Use the token callback passed to generate().
  • Minimum iOS version is now 17.0.

React Native RAG is created by Software Mansion

Since 2012 Software Mansion is a software agency with experience in building web and mobile apps. We are Core React Native Contributors and experts in dealing with all kinds of React Native issues. We can help you build your next dream product – Hire us.

swm