On-Device AI
Software Mansion's production patterns for on-device AI in React Native using React Native ExecuTorch.
Load at most one reference file per question. For hook API signatures, model constants, and configuration options, webfetch the relevant page from the official docs at https://docs.swmansion.com/react-native-executorch/docs/.
Decision Tree
Pick the right hook based on the AI task.
What AI task does the feature need?
│
├── Text generation, chatbot, or reasoning?
│ └── useLLM → see llm.md
│ ├── Text-only chat → standard useLLM
│ ├── Vision-language (image+text) → useLLM with VLM model
│ ├── Tool calling → configure with toolsConfig
│ └── Structured JSON output → getStructuredOutputPrompt
│
├── Understanding images?
│ ├── What's in this image? → useClassification → see vision.md
│ ├── Where are objects? → useObjectDetection → see vision.md
│ ├── Read text from image? → useOCR / useVerticalOCR → see vision.md
│ ├── Segment by class? → useSemanticSegmentation → see vision.md
│ ├── Segment per-instance? → useInstanceSegmentation → see vision.md
│ ├── Apply artistic style? → useStyleTransfer → see vision.md
│ ├── Generate image from text? → useTextToImage → see vision.md
│ └── Embed image as vector? → useImageEmbeddings → see vision.md
│
├── Speech or audio processing?
│ ├── Transcribe speech → useSpeechToText → see speech.md
│ ├── Synthesize speech → useTextToSpeech → see speech.md
│ └── Detect speech segments → useVAD → see speech.md
│
├── Text utilities?
│ ├── Convert text to vectors → useTextEmbeddings → see vision.md
│ └── Count tokens → useTokenizer
│
├── Real-time camera processing?
│ └── runOnFrame with VisionCamera v5 → see vision.md
│
└── Custom model (.pte)?
└── useExecutorchModule → see setup.md
Critical Rules
Call initExecutorch() before any other API. You must initialize the library with a resource fetcher adapter at the entry point of your app. Without it, all hooks throw ResourceFetcherAdapterNotInitialized.
Always check isReady before calling forward or generate. Hooks load models asynchronously. Calling inference methods before the model is ready throws ModuleNotLoaded.
Interrupt LLM generation before unmounting the component. Unmounting while isGenerating is true causes a crash. Call llm.interrupt() and wait for isGenerating to become false before navigating away.
Use quantized models on mobile. Full-precision models consume too much memory for most devices. React Native ExecuTorch ships quantized variants for all supported models.
Audio for speech-to-text must be 16kHz mono. Mismatched sample rates produce garbled transcriptions silently.
Audio from text-to-speech is 24kHz. Create the AudioContext with { sampleRate: 24000 } for playback.
Set pixelFormat: 'rgb' and orientationSource="device" for VisionCamera frame processing. The default yuv format produces incorrect results with ExecuTorch vision models. Missing orientationSource causes misaligned bounding boxes and masks.
References
| File |
When to read |
llm.md |
LLM chat (functional and managed), tool calling, structured output, token batching, context strategy, vision-language models (VLM), model selection, generation config |
vision.md |
Image classification, object detection, OCR, semantic segmentation, instance segmentation, style transfer, text-to-image, image/text embeddings, VisionCamera real-time frame processing with runOnFrame |
speech.md |
Speech-to-text (batch and streaming transcription with timestamps), text-to-speech (batch and streaming synthesis, phoneme input), voice activity detection, audio format requirements |
setup.md |
Installation with initExecutorch, resource fetcher adapters, model loading strategies (bundled, remote, local), download management, error handling with RnExecutorchError, custom models with useExecutorchModule, Metro config for .pte files |
Source: kingstinct/react-native-healthkit — distributed by TomeVault.
1---2name: kingstinct-react-native-healthkit-on-device-ai3description: On-Device AI4---56# On-Device AI78Software Mansion's production patterns for on-device AI in React Native using [React Native ExecuTorch](https://github.com/software-mansion/react-native-executorch).910Load at most one reference file per question. For hook API signatures, model constants, and configuration options, webfetch the relevant page from the official docs at `https://docs.swmansion.com/react-native-executorch/docs/`.1112## Decision Tree1314Pick the right hook based on the AI task.1516```17What AI task does the feature need?18│19├── Text generation, chatbot, or reasoning?20│ └── useLLM → see llm.md21│ ├── Text-only chat → standard useLLM22│ ├── Vision-language (image+text) → useLLM with VLM model23│ ├── Tool calling → configure with toolsConfig24│ └── Structured JSON output → getStructuredOutputPrompt25│26├── Understanding images?27│ ├── What's in this image? → useClassification → see vision.md28│ ├── Where are objects? → useObjectDetection → see vision.md29│ ├── Read text from image? → useOCR / useVerticalOCR → see vision.md30│ ├── Segment by class? → useSemanticSegmentation → see vision.md31│ ├── Segment per-instance? → useInstanceSegmentation → see vision.md32│ ├── Apply artistic style? → useStyleTransfer → see vision.md33│ ├── Generate image from text? → useTextToImage → see vision.md34│ └── Embed image as vector? → useImageEmbeddings → see vision.md35│36├── Speech or audio processing?37│ ├── Transcribe speech → useSpeechToText → see speech.md38│ ├── Synthesize speech → useTextToSpeech → see speech.md39│ └── Detect speech segments → useVAD → see speech.md40│41├── Text utilities?42│ ├── Convert text to vectors → useTextEmbeddings → see vision.md43│ └── Count tokens → useTokenizer44│45├── Real-time camera processing?46│ └── runOnFrame with VisionCamera v5 → see vision.md47│48└── Custom model (.pte)?49 └── useExecutorchModule → see setup.md50```5152## Critical Rules5354- **Call `initExecutorch()` before any other API.** You must initialize the library with a resource fetcher adapter at the entry point of your app. Without it, all hooks throw `ResourceFetcherAdapterNotInitialized`.5556- **Always check `isReady` before calling `forward` or `generate`.** Hooks load models asynchronously. Calling inference methods before the model is ready throws `ModuleNotLoaded`.5758- **Interrupt LLM generation before unmounting the component.** Unmounting while `isGenerating` is true causes a crash. Call `llm.interrupt()` and wait for `isGenerating` to become false before navigating away.5960- **Use quantized models on mobile.** Full-precision models consume too much memory for most devices. React Native ExecuTorch ships quantized variants for all supported models.6162- **Audio for speech-to-text must be 16kHz mono.** Mismatched sample rates produce garbled transcriptions silently.6364- **Audio from text-to-speech is 24kHz.** Create the `AudioContext` with `{ sampleRate: 24000 }` for playback.6566- **Set `pixelFormat: 'rgb'` and `orientationSource="device"` for VisionCamera frame processing.** The default `yuv` format produces incorrect results with ExecuTorch vision models. Missing `orientationSource` causes misaligned bounding boxes and masks.6768## References6970| File | When to read |71|------|-------------|72| `llm.md` | LLM chat (functional and managed), tool calling, structured output, token batching, context strategy, vision-language models (VLM), model selection, generation config |73| `vision.md` | Image classification, object detection, OCR, semantic segmentation, instance segmentation, style transfer, text-to-image, image/text embeddings, VisionCamera real-time frame processing with `runOnFrame` |74| `speech.md` | Speech-to-text (batch and streaming transcription with timestamps), text-to-speech (batch and streaming synthesis, phoneme input), voice activity detection, audio format requirements |75| `setup.md` | Installation with `initExecutorch`, resource fetcher adapters, model loading strategies (bundled, remote, local), download management, error handling with `RnExecutorchError`, custom models with `useExecutorchModule`, Metro config for `.pte` files |7677---78> Source: [kingstinct/react-native-healthkit](https://github.com/kingstinct/react-native-healthkit) — distributed by [TomeVault](https://tomevault.io).79<!-- tomevault:4.0:skill_md:2026-04-26 -->