Spring / Spring AI interview questions
1. What is Spring AI and what problem does it solve?
Spring AI is a framework in the Spring ecosystem that provides a portable, production-ready API for integrating large language model (LLM) capabilities into Java and Kotlin applications. It was created to solve a very concrete problem: every AI provider —...
2. What AI model providers does Spring AI support?
Spring AI supports a wide set of AI providers out of the box, and the list grows with each release. Providers are included as separate Spring Boot starter dependencies so you only pull in what you need....
3. What is the difference between ChatModel and ChatClient in Spring AI?
ChatModel and ChatClient exist at different levels of the Spring AI abstraction stack and serve different audiences in the same codebase. ChatModel is the low-level provider-facing interface....
4. How do you create and use a ChatClient in a Spring Boot application?
ChatClient is obtained from an auto-configured ChatClient.Builder bean that Spring Boot registers when a chat model starter is on the classpath. You inject the builder (not the client itself) so each service can establish its own default system prompt and...
5. What message types does Spring AI support in a Prompt?
A Prompt in Spring AI wraps a list of typed Message objects that correspond directly to the role-based message structure used by modern LLM APIs. Spring AI defines four concrete message types: Spring AI Message Types Class Role When to...
6. What is Retrieval-Augmented Generation (RAG) and how does Spring AI implement it?
Retrieval-Augmented Generation (RAG) is the technique of grounding an LLM's answer in documents you provide at query time, rather than relying solely on the model's training data. The model gets injected context that it uses to produce accurate, up-to-date, non-hallucinated...
7. What is a VectorStore in Spring AI and which implementations are available?
A VectorStore is Spring AI's abstraction over a vector database — a storage engine optimised for persisting high-dimensional float vectors (embeddings) and performing approximate nearest-neighbour (ANN) similarity search over them. It is the persistence backbone of the RAG pipeline....
8. What is an EmbeddingModel in Spring AI and why must the same model be used for ingestion and retrieval?
An EmbeddingModel in Spring AI is the abstraction for converting text into a dense float vector — a numerical representation where semantically similar texts produce vectors that are geometrically close. It is used in two places in the RAG lifecycle:...
9. How does PromptTemplate work in Spring AI?
PromptTemplate in Spring AI lets you define a prompt with named placeholders using {variableName} syntax and fill them in at runtime. This keeps prompt strings readable, testable as separate files, and decoupled from Java string concatenation....
10. What is structured output in Spring AI and how does it work internally?
Structured output is Spring AI's capability to have an LLM return JSON that is automatically deserialised into a Java object — a record, POJO, List , or Map — without writing any parsing code yourself. It solves the problem of...
11. What are Advisors in Spring AI and what built-in advisors are available?
Advisors in Spring AI are middleware components that wrap ChatClient request/response cycles. They form a chain — similar to servlet filters or Spring AOP around advice — where each advisor can inspect or mutate the request before it reaches the...
12. How does conversation memory work in Spring AI?
Conversation memory in Spring AI gives a ChatClient awareness of what was said earlier in a session — the model receives prior turns as part of every new request without the caller manually tracking message history. Without memory, every call...
13. What is function calling (tool use) in Spring AI and how do you register a function?
Function calling — also called tool use — is a model capability where, instead of fabricating an answer, the LLM decides to invoke a named function that your application provides, waits for the result, and uses it to compose its...
14. How do you stream responses from an LLM in Spring AI?
Streaming in Spring AI lets you consume LLM output token-by-token as a reactive Flux<String> (or Flux<ChatResponse> for full metadata) rather than waiting for the entire response to arrive. This is critical for chat UIs where users expect to see text...
15. What is the Document class in Spring AI and how is it used in RAG?
The Document class is Spring AI's core data carrier for textual content flowing through a RAG pipeline. It wraps a piece of text together with a metadata map and an optional embedding vector, giving every chunk a consistent identity regardless...
16. What is TokenTextSplitter and why is document chunking necessary?
Before documents can be embedded and stored in a VectorStore, they must be split into smaller pieces called chunks . TokenTextSplitter is Spring AI's built-in chunking utility that divides large documents into token-bounded segments while trying to preserve sentence and...
17. What DocumentReaders does Spring AI provide for loading content into the RAG pipeline?
A DocumentReader is the entry point of the RAG ingestion pipeline — it reads raw source material and converts it into a List<Document> that can then be chunked and embedded. Spring AI ships several ready-made readers so you do not...
18. What is the Spring AI ETL pipeline and how does it work?
The Spring AI ETL (Extract-Transform-Load) pipeline is a composable data processing abstraction for building RAG ingestion workflows. Rather than wiring readers, splitters, and vector stores manually in imperative code, ETL lets you declare a pipeline as a chain of typed...
19. How does Spring AI integrate with Spring Boot auto-configuration?
Spring AI follows standard Spring Boot auto-configuration conventions, which means zero boilerplate for the common case. When you add a provider starter to your dependencies and supply the required properties, Spring Boot auto-configures the AI beans you need without any...
20. What are ChatOptions in Spring AI and how do you apply them per-request?
ChatOptions is the interface through which you pass inference parameters — temperature, max tokens, top-p, stop sequences, model name — to the model for a specific call. Spring AI separates these from the core Prompt messages so they can be...
21. What is the SearchRequest API in Spring AI's VectorStore?
SearchRequest is the query object you pass to VectorStore.similaritySearch() . It encapsulates the query string plus optional filters — maximum results, similarity threshold, and metadata filter expressions — so you can constrain what documents come back rather than retrieving everything...
22. How does Spring AI support multimodal inputs such as images?
Multimodal support in Spring AI means sending both text and non-text content — images, audio — to models that can process them (GPT-4o, Claude 3, Gemini, Llama 3.2 Vision). The UserMessage class accepts a list of Media objects alongside the...
23. What is image generation in Spring AI and how do you use ImageModel?
Spring AI provides an ImageModel abstraction for generating images from text descriptions (text-to-image). Providers that support it include OpenAI (DALL-E 2, DALL-E 3), Azure OpenAI, and Google Vertex AI (Imagen)....
24. How does Spring AI handle observability and what metrics does it expose?
Spring AI integrates with Spring Boot's Micrometer-based observability stack out of the box. When spring-ai-*-spring-boot-starter is on the classpath alongside spring-boot-starter-actuator and a Micrometer registry (Prometheus, OpenTelemetry, Zipkin, etc.), Spring AI auto-configures instrumentati
25. How do you test Spring AI components without calling real AI APIs?
Testing AI-integrated code without hitting real provider APIs is important for cost control, speed, and determinism. Spring AI provides two main strategies: using a MockChatModel / test double, or using the auto-configured @SpringBootTest with a property override that points to...
26. What is the Spring AI MCP (Model Context Protocol) integration?
The Model Context Protocol (MCP) is an open standard, originally proposed by Anthropic, that defines how AI models communicate with external tools and data sources in a structured way. Spring AI 1.x introduced first-class support for MCP, making it straightforward...
27. What is the role of MetadataEnricher and KeywordMetadataEnricher in Spring AI?
Metadata enrichers are DocumentTransformer implementations that augment each Document 's metadata map before it is stored in the VectorStore. Richer metadata improves retrieval quality because metadata filter expressions in SearchRequest can then precisely target relevant subsets — for example, f
28. What are the Spring AI Chat Model options for controlling response determinism?
Response determinism in LLMs is primarily controlled through two inference parameters: temperature and top-p (nucleus sampling). Both are set via ChatOptions in Spring AI and work together to shape how randomly the model selects the next token at each step...
29. What is the Spring AI Agentic pattern and how does it differ from a single-turn chat call?
An agent in the context of Spring AI is an autonomous loop where an LLM iteratively reasons, selects tools, executes them, incorporates results, and reasons again until it can produce a final answer — all without a human in the...
30. What does the spring-ai-bom do and why should you use it?
The spring-ai-bom (Bill of Materials) is a Maven/Gradle POM that centralises version declarations for all Spring AI modules. By importing the BOM you avoid specifying versions on individual Spring AI starter dependencies, eliminating version mismatch bugs and ensuring all Spring...
31. What is PgVector and how do you configure it as a VectorStore in Spring AI?
PgVector is an open-source PostgreSQL extension that adds a vector column type and approximate nearest-neighbour index operators to Postgres. Spring AI's PgVectorStore uses it to store document embeddings and run similarity searches directly inside your existing Postgres database — no...
32. How does Spring AI's retry and resilience mechanism work for LLM API calls?
Network-level failures and provider rate limits are unavoidable when calling external AI APIs. Spring AI integrates with Spring Retry to automatically retry failed model calls using exponential backoff, shielding application code from transient errors....
33. What is the Spring AI Evaluation framework and how do you use it?
The Spring AI Evaluation framework provides programmatic tools for assessing the quality of LLM responses — particularly RAG outputs — without manual human review on every run. This is important for catching prompt regressions and measuring retrieval quality as your...
34. How do you use Spring AI with Spring WebFlux for a reactive AI endpoint?
Spring AI integrates naturally with Spring WebFlux's reactive pipeline. Because LLM streaming returns a Flux<String> or Flux<ChatResponse> , you can return it directly from a WebFlux controller with zero blocking, delivering tokens to the browser as Server-Sent Events (SSE) as...
35. What are the Spring AI Spring Initializr options and how do you bootstrap a project?
The fastest way to start a Spring AI project is through start.spring.io . The Spring Initializr now includes Spring AI dependencies as first-class options in the AI category....
36. What is the Spring AI content moderation strategy and how do you implement it?
Spring AI does not ship a built-in content moderation system, but the framework provides the right extension points — primarily Advisors — to implement moderation as a pre- and post-processing step in the ChatClient pipeline. This keeps moderation logic reusable...
37. How does Spring AI support multi-tenancy where different users need different LLM configurations?
Multi-tenancy in Spring AI — where different users, teams, or tenants need different models, API keys, or system prompts — is addressed through a combination of per-request ChatOptions , scoped ChatClient instances, and conversation ID isolation in ChatMemory . There...
38. What is the Spring AI AudioModel and how does it support speech synthesis?
Spring AI includes an AudioModel (specifically SpeechModel ) abstraction for text-to-speech (TTS) generation. This covers converting text responses to spoken audio — useful for voice assistants, accessibility features, and audio content pipelines.
39. How does Spring AI handle prompt injection attacks?
Prompt injection is an attack where a user (or data retrieved from an external source) includes text that overrides or subverts the system prompt instructions — e.g., a document retrieved in a RAG pipeline that says Ignore all previous instructions...
40. What are the performance tuning strategies for a Spring AI RAG application at scale?
When a RAG application moves from prototype to production load, several bottlenecks emerge. Addressing them requires tuning at the ingestion layer, retrieval layer, LLM call layer, and infrastructure layer....
41. 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...
42. What is semantic caching in Spring AI and how would you implement it?
Semantic caching is an optimisation where you cache LLM responses not by exact query string match but by semantic similarity — if a new question is semantically close enough to a previously answered one, return the cached answer rather than...
43. How does Spring AI integrate with Spring Security for securing AI endpoints?
Spring AI does not ship its own security layer — it relies entirely on Spring Security, which is the standard approach for all Spring Boot APIs. Securing AI endpoints is exactly the same as securing any REST endpoint, with a...
44. How does Spring AI's Document metadata filtering work with PgVector and what filter operators are available?
Spring AI's metadata filter API provides a provider-neutral expression builder that gets translated into native filter syntax for each VectorStore. For PgVector, Spring AI translates filter expressions into SQL WHERE clauses applied alongside the vector similarity search, so you can...