Skip to main content
rag.open returns a session that holds a corpus. You ingest documents into it, then either retrieve chunks or ask a question that gets answered from them.

Open a session

open loads both models, downloading them first when needed, then creates the pipeline. It throws when a model fails to load.
The native core keeps one RAG pipeline per process, so React Native allows one open session at a time. A second open() throws rather than silently replacing the first. Call close() before opening another.

RagConfig

Ingest

RagDocument is { text?, filePath?, id?, metadata? }. Ingesting a document with neither text nor a readable file throws.
filePath needs the optional react-native-fs dependency, since the SDK core has no JavaScript filesystem. Without it, pass the text instead.

Search and query

RagResult extends GenerationResult, so it carries answer, sources, and the same metrics block as any generation: inputTokens, outputTokens, timeToFirstTokenMs, tokensPerSecond, requestId, model. query takes optional LlmOptions, so reasoning and sampling work the same as on llm.generate.

Streaming a query

Hermes cannot iterate this with for await...of. Use the manual loop above.

Stats, clear, close

Every verb throws once the session is closed, except close() itself, which is idempotent.

One document at a time

Because only one session can be open, a document viewer that queries one file at a time should close the previous session first. Otherwise the second open() throws.

Other capabilities

Embeddings and rerank on their own

Voice sessions

The other session type

Generate

Sampling and reasoning options

Error handling

SDKException reference