Spring / Spring AI interview questions
How does Spring AI support the Ollama provider for local model development?
Ollama is an open-source tool that downloads and runs large language models locally on your machine — no API key, no internet connection required once the model is downloaded. Spring AI's Ollama integration makes local model development as seamless as using a cloud provider: the same ChatClient, EmbeddingModel, and Advisor abstractions work identically.
Setup involves running the Ollama server and pulling a model:
brew install ollama # macOS ollama serve # starts the local API server at http://localhost:11434 ollama pull llama3 # download Llama 3 (4-8 GB depending on quantisation) ollama pull nomic-embed-text # download an embedding model
Spring Boot configuration:
<dependency> <groupId>org.springframework.ai</groupId> <artifactId>spring-ai-ollama-spring-boot-starter</artifactId> </dependency>
spring.ai.ollama.base-url=http://localhost:11434 spring.ai.ollama.chat.options.model=llama3 spring.ai.ollama.embedding.options.model=nomic-embed-text
Ollama supports chat, embeddings, and streaming. For CI environments, Testcontainers provides an OllamaContainer that downloads and starts an Ollama Docker container with a specified model as part of the test lifecycle — enabling fully automated, offline AI integration tests without any external API credentials:
@Container static OllamaContainer ollama = new OllamaContainer("ollama/ollama:latest") .withModel("phi3:mini");
More Related questions...