Spring Boot
models-spring-boot-starter turns an application-provided Models runtime into
a Spring AI ChatModel. Model resolution remains explicit: the application
adds one ModelJar marker and exposes the resulting TextGenerationModel as a
bean. The starter applies the configured chat template and sampling defaults.
The Models and Vectors starters are tested together on Spring AI 1.1.4, 1.1.8, and 2.0.0. They contribute separate chat and vector-store beans and do not replace one another.
Development Launchers
Spring Boot’s optimized development launch adds
-XX:TieredStopAtLevel=1. That starts the application quickly by limiting
HotSpot to the C1 compiler, but it also prevents the Vector API inference
kernels from being optimized by C2. A model request can consequently appear to
hang while it is actually executing the unoptimized kernels.
Disable that startup optimization for bootRun:
tasks.named('bootRun') {
optimizedLaunch = false
jvmArgs '--add-modules', 'jdk.incubator.vector'
}
tasks.named<org.springframework.boot.gradle.tasks.run.BootRun>("bootRun") {
optimizedLaunch.set(false)
jvmArgs("--add-modules", "jdk.incubator.vector")
}
For the Spring Boot Maven plugin, use:
<configuration>
<optimizedLaunch>false</optimizedLaunch>
<jvmArguments>--add-modules jdk.incubator.vector</jvmArguments>
</configuration>
In IntelliJ IDEA, open the Spring Boot run configuration, choose
Modify options, and select Disable launch optimization.
Models checks this JVM prerequisite before loading a pure-Java model. If a C1-only or interpreted-only launch is detected, startup fails immediately with the same remediation instead of beginning impractically slow inference.
Dependencies
Use the Spring AI BOM or an existing Spring AI provider starter to select the
framework version. The explicit spring-ai-model dependency below is the
smallest standalone setup:
dependencies {
implementation("org.springframework.ai:spring-ai-model:2.0.0")
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"
)
implementation("com.integrallis:models-spring-boot-starter:0.5.20")
}
Provide the Model
import static org.modeljars.catalog.Qwen3_0_6b_Q4_0.MODEL;
import com.integrallis.models.api.TextGenerationModel;
import org.modeljars.ModelJars;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
class LocalModelConfiguration {
@Bean(destroyMethod = "close")
TextGenerationModel localModel() {
return ModelJars.open(MODEL);
}
}
When a TextGenerationModel bean is present, the starter registers
ModelsSpringAiChatModel under the stable bean name modelsChatModel. An
InferenceBackend bean can be supplied instead; a high-level
TextGenerationModel takes precedence when both exist. If neither exists, the
starter does not create a phantom chat-model bean.
When Spring Boot provides an ObservationRegistry, the starter passes it to
the adapter automatically. Blocking and streaming local inference therefore
emit Spring AI’s standard gen_ai.client.operation observations with
gen_ai.system=integrallis and the local model identity. No application-side
counter or wrapper is required.
When application metrics are available, the starter registers Spring AI’s
standard chat and embedding meter handlers unless another provider already
supplied them. The Models auto-configuration runs after the metrics and
observation configuration supplied by both supported Spring Boot generations,
so an Actuator-created registry is detected without application ordering or
wiring. Exact prompt and completion counts from the local adapter are
exported as standard gen_ai.client.token.usage counters with
gen_ai.token.type=input and gen_ai.token.type=output. Applications replacing
a hosted provider do not need to retain that provider’s starter merely to keep
token metrics, and Models does not pin the application-owned Spring AI version.
Other Spring AI model-provider beans can coexist. Inject the local model by
name when an application has more than one ChatModel:
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
@Component
final class LocalAssistant {
private final ChatModel model;
LocalAssistant(@Qualifier("modelsChatModel") ChatModel model) {
this.model = model;
}
}
Configure Chat and Sampling
integrallis:
models:
chat-template: chatml-no-think
sampling:
temperature: 0.0
top-p: 0.9
top-k: 40
max-tokens: 128
seed: 42
repetition-penalty: 1.0
stop-sequences:
- "</answer>"
These values become immutable adapter defaults. Non-null Spring AI
ChatOptions on an individual Prompt override temperature, top-p, top-k,
maximum tokens, and stop sequences for that request without mutating the bean.
The configured seed and repetition penalty remain in effect.
Blocking and Streaming
The injected bean implements both Spring AI paths:
String answer = model.call("Summarize the retrieved policy.");
model.stream(new Prompt("List the retrieved facts."))
.map(response -> response.getResult().getOutput().getText())
.doOnNext(System.out::print)
.blockLast();
Streaming has the same ordering and error semantics described in Spring AI streaming. Blocking model inference runs off the Reactor subscriber thread.
Add Vectors for RAG
Add the Vectors starter to expose a standard Spring AI VectorStore beside the
local Models ChatModel:
dependencies {
implementation("com.integrallis:vectors-spring-boot-starter:0.1.34")
}
java-vectors:
index-type: HNSW
quantizer: SQ8
When the application provides a Spring AI EmbeddingModel, the Vectors starter
infers its dimension and contributes JavaVectorsVectorStore. Spring AI’s
ChatClient and retrieval advisors can then use modelsChatModel and that
standard VectorStore without adapter-specific glue.
Retrieval advisors assemble context but do not prove that the generated answer is supported. Apply RAG Validation when the application requires retrieval screening, citation validation, and bounded fallback.
