@rn-ai/openmed
v0.2.0
Published
OpenMed clinical analysis and AI SDK prompt-sanitizing middleware for React Native
Maintainers
Readme
@rn-ai/openmed
OpenMed 1.9.1 clinical NER, PII extraction, de-identification, and AI SDK 7 prompt middleware. This is deliberately not a language-model provider.
Native installation
The package links OpenMed through a Nitro module. Bun applications must list @rn-ai/openmed in trustedDependencies, or run bunx rn-ai install-native before CocoaPods/Gradle configuration. Published native artifacts are SHA-256 verified by the installer; maintainers build the pinned upstream v1.9.1 tag locally with scripts/build-ios-xcframework.sh and the upstream Android Gradle project.
No model weights are included. Runtime download into the app-private cache is the recommended delivery path on both iOS and Android. A local/bundled path remains available for development or managed distributions, but a normal app should not ask the user to locate an OpenMed model folder.
Model layout
- Android uses ONNX. The model directory must contain
model_int8.onnx,model_fp16.onnx, ormodel.onnxfor the correspondingvariant;int8is the memory-first default.id2LabelPathcan override the label map. - iOS supports
mlxmodel directories andcoremlmodel files. Core ML requiresid2LabelPath; tokenizer name/folder andmaxSequenceLengthare configurable. The iOS default is MLX.
Download and use the iOS MLX model
OpenMed models are directories, so use remote-directory. This is the verified ClinicalE5 Small
33M MLX preset used by the example app on a physical iPhone or iPad:
import { createOnDeviceRuntime } from '@rn-ai/core'
import { createOpenMedEngine } from '@rn-ai/openmed'
const revision = '0b72ee8568236cbcf991212e729cbd65ca26aa7c'
const modelUrl = (path: string) =>
`https://huggingface.co/OpenMed/OpenMed-PII-ClinicalE5-Small-33M-v1-mlx/resolve/${revision}/${path}?download=1`
const runtime = createOnDeviceRuntime()
const openmed = createOpenMedEngine({
runtime,
model: {
source: {
kind: 'remote-directory',
directoryName: 'openmed-pii-clinicale5-small-33m-mlx-0b72ee85',
artifacts: [
{
path: 'config.json',
url: modelUrl('config.json'),
sizeBytes: 6_528,
sha256: '04a9234e83fec48eb9efef644abeb095c6c8c4296c7d089b9a5292647ab9d29f',
},
{
path: 'id2label.json',
url: modelUrl('id2label.json'),
sizeBytes: 2_598,
sha256: '40f57c6fa3d84775c7d3cd58d6ef3c4736250261f08572cbbaef1290b577c898',
},
{
path: 'weights.safetensors',
url: modelUrl('weights.safetensors'),
sizeBytes: 133_032_689,
sha256: '87fff672bfae2ee052b0c046b5cbe1bc14792b93eaeca2b2526ac6dd2926cdc9',
},
],
},
backend: 'mlx',
maxSequenceLength: 512,
},
})
await openmed.control.download({
onProgress: ({ fraction }) => console.log(`${Math.round(fraction * 100)}%`),
})
await openmed.control.prepare()
const note = 'Patient Jane Doe can be reached at [email protected].'
const result = await openmed.deidentify(note, { policy: 'hipaa_safe_harbor' })
await openmed.control.unload()The runtime downloads the files concurrently, verifies each one, and exposes the directory only after the complete manifest succeeds. iOS MLX is unavailable in the Simulator.
For Android, use the same remote-directory pattern with a revision-pinned ONNX repository. The
directory must include model_int8.onnx, model_fp16.onnx, or model.onnx for the configured
variant, plus any tokenizer/config files required by that model. Pin every artifact's exact size
and SHA-256; this package does not currently claim a built-in verified Android preset.
Preparation is always explicit. Call analyze, extractPii, deidentify, or wrap a V4 model with createOpenMedMiddleware. Middleware recursively sanitizes textual system/user/assistant content, text-backed file parts, tool inputs/results, and approval reasons before inference. It reports detected spans only through onDetected and never re-identifies model output.
