Skip to main content

Intelligence Service

Intelligence Service is responsible for providing DataSapien's patented on-edge intelligence approach. Intelligence Service allows access to:

  • Rules - these are the first level of intelligence and static in nature
  • AI Models - Generative AI Models designed to work in a wide range of fields

All intelligence runs on the device: model files are downloaded once and inference happens locally, so user data never has to leave the device to be used with a model.

Use Cases

Running an AI Model On-Device

AI models are provisioned as Managed AI Models on the Orchestrator. The typical lifecycle in your host app is:

  1. Discover available models with getManagedAIModels (or getManagedAIModel for a single one). These definitions are synchronized from the Orchestrator. The name returned here is the model's programmatic name — you pass it to every model-file related call.
  2. Check the model files with isModelFilesDownloaded. Model definitions and model files are separate: the definition arrives with sync, the files are downloaded on demand.
  3. Download if needed with downloadModelFiles. It reports progress via a callback and the download keeps running while your app is in the background.
  4. Load the model with loadModel(name, key, modelParams). The key is an alias you choose for this loaded instance — every later call (invokeModel, isModelLoaded, stopModelInference, unloadModel) refers to the model by this key. ModelParams tunes how the model is loaded: nCtx (context window, default 512), nBatchSize (default 64), nThreads (defaults to available CPU cores, minimum 2) and nGpuLayers (default 20).
  5. Verify with isModelLoaded(key) if needed.
  6. Invoke with invokeModel(key, prompts, inferenceParams). Prompts are an array of role / content messages, and InferenceParams controls generation: temperature (default 0.8), maxTokens (default 10.000), topP (default 0.95) and optional topK. Streaming output is delivered chunk by chunk through the onStream callback and the full answer arrives in onSuccess.
  7. Clean up with unloadModel(key) when you are done to release memory. To cancel an ongoing generation, call stopModelInference(key).
let intelligence = DataSapien.getIntelligenceService()

if !intelligence.isModelFilesDownloaded(name: "gemma-3n") {
intelligence.downloadModelFiles(
name: "gemma-3n",
onProgress: { progress in },
onSuccess: { }
)
}

intelligence.loadModel(name: "gemma-3n", key: "assistant", onSuccess: {
intelligence.invokeModel(
key: "assistant",
prompts: [Prompt(role: .user, content: "Suggest a savings plan")],
onStream: { chunk in },
onSuccess: { answer in
intelligence.unloadModel(key: "assistant")
}
)
})

To manage local storage: getDownloadedModelsList returns the names of all models whose files are on the device, and deleteModelFiles(name) removes a model's files.

Using Intelligence in Journeys

The same functions are available to Journey Script steps through the global IntelligenceService object, so a Journey can run a one-shot inference as part of its flow — for example generating a personalized suggestion between two screens:

await IntelligenceService.loadModel("gemma-3n", "journey-model");
const answer = await IntelligenceService.invokeModel("journey-model", [
{ role: "user", content: "Summarize the user's answers: " + context.answers }
]);
await IntelligenceService.unloadModel("journey-model");

The result can be written into the Journey Context and displayed on a following Screen step.

Rules & Triggers

Rules are designed on the Orchestrator and deployed to Mobile SDK instances. Their purpose is to do work that requires no UI, outside of Journeys — for example reading existing data to derive a new value, or changing the user's state.

  • Rule definitions are synchronized during DataSapien.setup; call syncRules to synchronize explicitly at any other time.
  • A rule can be flagged to run on SDK initialization; such rules are executed automatically during setup.
  • To run rules yourself: runRules evaluates all of them, and runRule(name) evaluates a specific rule.
warning

Note that rule evaluation may be limited or completely impossible when your host app is in the background because of the limitations imposed by mobile operating systems.

Hallucinations & Fact Checking

AI models, because of their generative nature, are prone to hallucinations. DataSapien architecture allows you to fact check AI output by:

  1. Writing scripts to implement simple accept / reject algorithms
  2. Using an additional AI Model: feeding first AI output to an additional AI model

Intelligence Service Functions

To access IntelligenceService functions, get its instance from the DataSapien object: DataSapien.getIntelligenceService().

See the full function list per platform in the Intelligence Service API Reference.