Spring AI and LangChain4j
45 questions in 16 subtopics.
Calling LLMs from Java
A Java developer asks why an LLM answer differs each time for the same prompt and sometimes ignores the required JSON format. Explain the causes and what a Java service can do about them.Using Spring AI 1.x, write the code for a Spring Boot service method that sends a system instruction and a user question to a chat model and returns the text answer, and explain where the model and API key are configured.Design how a Spring Boot service calls an external LLM API reliably in production: timeouts, retries, rate limits, streaming, and protecting the service when the provider is slow.Ten teams in your company want to call LLM providers directly from their Java services with their own API keys. As the architect, what would you put in place before this spreads further?Spring AI abstractions
Explain the roles ofChatModel, ChatClient, EmbeddingModel and VectorStore in Spring AI and how they relate to each other.Using Spring AI, how would you get a typed Java object back from a model, for example extracting a record InvoiceData(String vendor, BigDecimal total, LocalDate date) from invoice text?In Spring AI, what are advisors, and how would you use them to add chat memory and retrieval to a ChatClient?Your team must choose between Spring AI and LangChain4j for a new Java service that does retrieval, tool calling and chat memory. How would you compare them?Retrieval-augmented generation in Java
Explain the steps of retrieval-augmented generation for a Java service that answers questions from internal policy documents.Design a RAG-based support assistant in Spring Boot over 200,000 documents that change daily, where users must only see answers from documents they are allowed to read.Several teams are building RAG features with their own vector stores and ingestion code. Design a shared retrieval platform for Java teams.The company wants an assistant over all internal knowledge (wikis, tickets, code, contracts). As the senior technical leader, what are the key risks and how do you sequence the programme?Tool calling
Show how to expose a Java method as a tool that a model can call in Spring AI 1.x, for example to look up an order status, and explain what the model actually does.An assistant built with tool calling can cancel orders. A tester convinced it to cancel another customer's order by including an order number in a pasted message. How would you fix the design?Your company wants to expose internal capabilities to AI assistants using the Model Context Protocol (MCP). How would you design and govern MCP servers built with Java?Product leaders want AI agents that can take actions in customer accounts (refunds, plan changes) on their own. As the senior technical leader, how do you decide how much autonomy to allow?Evaluating and testing AI features
How would you write automated tests for a Spring Boot service that usesChatClient to summarise support tickets, without calling a real model on every build?Design an evaluation process for a RAG feature before each release, including what you measure and how.Your board asks how the company ensures AI features are accurate and safe. As the senior technical leader, what governance would you put in place?Cost and latency
What drives the cost and latency of an LLM call from a Java service, and how do you measure them?An AI feature's monthly cost is ten times the estimate. How would you reduce cost without hurting quality badly?AI spend across your organisation is growing fast without clear value tracking. How would you manage it?As the senior technical leader, how would you decide between using hosted frontier models, open-weight models you host yourselves, or a mix, for Java-based AI features?Advisors and chat memory
A Spring AI chatbot forgets what the user said in the previous message. Show how to add chat memory per user conversation withChatClient, and explain where the messages are stored and how many are sent to the model.Write a custom Spring AI advisor that removes email addresses from the user message before it reaches the model and records the token usage after the call. How do advisors chain, and how do you control their order?Several product teams build assistants with Spring AI and each implements memory, retrieval, guardrails and logging differently. Design a shared set of advisors and policies the platform team provides.Prompt templates and structured output
Use aPromptTemplate stored in src/main/resources/prompts/summary.st with placeholders for the ticket text and the maximum number of bullet points. Show how to render and send it with ChatClient, and explain what happens if the ticket text itself contains curly braces.A service uses chatClient.prompt().user(text).call().entity(new ParameterizedTypeReference<List<LineItem>>() {}) and about 3 percent of calls fail with a JSON parsing exception, sometimes because the model wraps JSON in markdown fences. How do you make structured output reliable?Model providers
How does Spring AI let you switch between model providers such as OpenAI, Anthropic, Ollama and Amazon Bedrock? What changes in code and configuration, and what does not stay the same?A service must use a cheap fast model for classification, a stronger model for complex answers, and fall back to a second provider when the first is down. How would you configure multipleChatModels and route between them in Spring AI?Document ingestion and ETL
Build a Spring AI ingestion pipeline that reads PDF manuals, splits them into chunks, adds the source file name and page as metadata, and writes them to a vector store. Name the classes you would use.Documents in your RAG system are updated and deleted daily, and users get answers from outdated versions. How would you design incremental ingestion so the vector store stays in sync with the source?Multimodal, audio and moderation
Send a photo of a receipt plus a question to a vision-capable model with Spring AIChatClient, and transcribe a customer voicemail to text. Which APIs do you use?A community app lets users post text and images, and the product team wants AI moderation before content is published. Design the flow with Spring AI, including what happens when the moderation service is slow or unsure.Embeddings and vector stores
Explain how embeddings and vector similarity search work in Spring AI with PGvector. What does aSearchRequest with topK, a similarity threshold and a metadata filter do?Retrieval quality dropped after the team switched the embedding model to a newer one and re-ran ingestion only for new documents. Some queries now return unrelated chunks. Explain the cause and the migration plan you would use.Teams are adopting different vector stores (PGvector, Elasticsearch, Redis, a hosted vector database). Define the company's approach to vector storage for Java services.Streaming responses
Return a streaming answer from a Spring MVC endpoint so the browser shows tokens as they arrive. Show the Spring AI call and the controller method, and say what happens when the user closes the tab.Streaming answers work locally but in production users see the whole answer appear at once after 20 seconds, and some streams are cut off after 60 seconds. What do you investigate and fix?Observability of AI calls
What observability does Spring AI provide out of the box for chat and embedding calls, and what would you put on a dashboard for an AI feature?Leadership asks for monthly reporting of AI cost, quality and incidents across 20 services using Spring AI. Design the telemetry and the reporting pipeline.AI call error handling
A Spring AI call fails in production with HTTP 429 from the provider, another with a context length exceeded error, and a third hangs for two minutes. Explain how Spring AI's retry settings behave and how you handle each case.An AI-powered support assistant must stay usable when the model provider has an outage or rate limits during peak hours. Design the error handling and degradation strategy.Spring AI versions and migration
Your services use Spring AI 0.8 milestone code written in 2024 and you want to move to Spring AI 1.x with Spring Boot 3.5. What kinds of breaking changes do you expect and how do you plan the migration?Generative AI frameworks for Java (Spring AI, LangChain4j, provider SDKs) change quickly, and the next Spring AI major is tied to Spring Boot 4. As the senior technical leader, how do you manage framework choice and upgrade risk for AI features across the company?No question matches these choices.