Spring / Spring AI interview questions
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 model and inspect or transform the response before it returns to the caller. The base interface is RequestResponseAdvisor.
Advisors are registered on the ChatClient.Builder:
ChatClient client = ChatClient.builder(chatModel)
.defaultAdvisors(
new MessageChatMemoryAdvisor(new InMemoryChatMemory()),
new QuestionAnswerAdvisor(vectorStore),
new SimpleLoggerAdvisor()
)
.build();Spring AI ships several built-in advisors:
- MessageChatMemoryAdvisor — prepends stored conversation history to every request and appends new exchanges after the response. Enables stateful multi-turn conversations without manual history management.
- QuestionAnswerAdvisor — performs VectorStore similarity search before each call and injects retrieved documents into the prompt as context (the RAG advisor).
- SimpleLoggerAdvisor — logs the full request and response for debugging and observability.
- SafeGuardAdvisor — content safety advisor that can block or filter prompts containing disallowed content.
Advisors execute in registration order for requests and in reverse order for responses — the same wrapping semantics as a filter chain. Writing a custom advisor means implementing RequestResponseAdvisor, adding your logic, and registering it in the builder.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
