Context aware Spring AI chat microservice A developer demonstrated how to build a context-aware Spring Boot chat microservice that connects to Google's Gemini API using Spring AI's ChatMemory Advisor to maintain conversation history. The implementation persists chat sessions across application restarts by backing the memory with a file-based H2 database via JdbcChatMemoryRepository, keyed to unique user sessions. By default, Large Language Models LLMs are completely stateless . Every API call you make to Google Gemini is treated like a first-time introduction. If a user says " My name is Alex " in request one, and " What is my name? " in request two, Gemini will not know the answer. To build a true chatbot experience, your microservice needs to remember the conversation history. In this post, we will build a Spring Boot microservice that connects to the Gemini API , uses Spring AI's ChatMemory Advisor to maintain context, and backs up that history using a persistent H2 database mapped to unique user sessions. The Architecture Add the required dependencies to your pom.xml. This includes the Spring AI starter for Gemini, the chat memory module, and the H2 database driver.