Models
Models is an in-process inference library for Java applications. Inference is the work of running a trained model to produce an answer. With Models, an application can load an open-weight model to generate text, synthesize speech, create embeddings, or rerank retrieved documents without starting Python, calling a separate model server, or sending prompts over the network.
Models loads GGUF files, supported Hugging Face Safetensors directories, and the architecture-specific CACT artifact used by Needle 2. GGUF packages model metadata, tokenizer data, and commonly quantized weights in one file. Safetensors checkpoints keep configuration and tokenizer files beside one or more mapped weight shards.
Running the file efficiently requires more than parsing it. The runtime must map large weight tensors into memory, convert text to tokens, and execute every transformer layer. Generative models also retain an attention history in a key-value (KV) cache and select and stream each new token; bidirectional encoders instead process and pool the complete sequence. The most expensive steps are numeric kernels limited by memory bandwidth and SIMD throughput. Models implements that complete pipeline in Java 25 and uses the Vector API to reach the CPU’s SIMD instructions.
backend-java executes every inference kernel in Java. backend-native runs
the same Java pipeline but replaces selected, measured bottleneck kernels with
a small Models-owned Rust library through Java’s Foreign Function and Memory
(FFM) API. It does not embed or invoke llama.cpp or Ollama.
The optional backend-cuda module keeps that graph in Java while Models-owned
Rust kernels, compiled to PTX and carried inside the jar, run the K-quant
projections and grouped-query decode attention on an NVIDIA GPU. It performs an
explicit readiness pass and falls back to the Vector API when the device, memory
capacity, or artifact is not eligible.
New to local model execution? Start with Inference Concepts.
Run a Model
Add the ModelJars runtime and one qualified model marker:
dependencies {
implementation("org.modeljars:modeljars:0.1.78")
implementation(
"org.modeljars.huggingface:" +
"ggml-org.qwen3-0.6b-gguf.q4_0:" +
"3.0.0-q4_0.1"
)
}
The marker supplies the exact model descriptor; the application does not construct a model-file path:
import static org.modeljars.catalog.Qwen3_0_6b_Q4_0.MODEL;
import com.integrallis.models.api.SamplingOptions;
import com.integrallis.models.runtime.chat.ChatMessage;
import java.util.List;
import org.modeljars.ModelJars;
var options = SamplingOptions.builder()
.temperature(0.0f)
.maxTokens(128)
.build();
try (var runtime = ModelJars.openRuntime(MODEL)) {
var prompt = runtime.chatTemplate().render(
List.of(ChatMessage.user("Why is local inference useful?")));
System.out.println(runtime.model().generate(prompt, options));
}
Continue with Using Models for streaming and diagnostics, or Inference Pipeline for tokenizer, context, prefill, logits, and rewind access. Framework users can go directly to LangChain4j, Spring AI, or Spring Boot.
Published Modules
| Artifact | Purpose |
|---|---|
|
Application-facing API and generation-runtime facade |
|
Backend, tokenization, sampling, streaming, metadata, and diagnostics contracts |
|
Generation loop, prompt-prefix reuse, sampling, and streaming |
|
In-process text-to-speech, normalized PCM streaming, and WAV encoding |
|
In-process, pure-Java execution of ONNX graphs; never ONNX Runtime |
|
GGUF, supported Safetensors, and CACT model loading with Java 25 Vector API execution |
|
Optional Rust-authored PTX projection and decode-attention acceleration on qualified NVIDIA GPUs |
|
The Java backend with selective Rust/FFM bottleneck-kernel substitution |
|
Java access to Apple’s OS-managed on-device Foundation Models runtime |
|
Framework-neutral grounding, citation, abstention, and extractive-fallback policy |
|
Pure-Java WordTour semantic-order models |
|
LangChain4j blocking and streaming chat, embedding, and cross-encoder scoring adapters |
|
Spring AI blocking and streaming chat, embedding, and document-reranking adapters with qualified
|
|
Spring Boot auto-configuration for a local Models-backed Spring AI |
|
Optional Models-to-Vectors storage and semantic-cache bridge |
|
Adaptive, explainable routing and failover across local and hosted application clients |
|
Typed, bounded, calibrated decisions in one pass, with no decode loop |
Start with Using Models, then select an exact artifact from Model Support.
