Skip to main content

Posts

Spring AI: Working with Google Vertex AI (Gemini)

Greetings! 1. Install Google Cloud CLI 2. Login 3. Select your project 4. Create Application Default Credentials 5. Verify everything Running inside Google Cloud Running outside Google Cloud Over the last few articles, we've learned the fundamentals of Spring AI using different concepts like prompts, memory, RAG, tools, and agents. In this article, we'll focus on something much simpler—connecting a Spring Boot application to Google Vertex AI and chatting with Gemini . If you've already used the OpenAI integration, you'll notice that the application code is almost identical. The biggest difference is authentication , and that's exactly what we'll cover. Why Vertex AI? Google provides two ways to access Gemini models. Google AI Studio  - Great for learning and quick experiments using an API key. Google Vertex AI -  Enterprise platform for production workloads. Vertex AI offers: Enterprise authentication using Google Cloud IAM Security and acce...

Spring AI: Tool Calling with Spring AI

Greetings! Why Tool Calling Exists What Is a Tool? Creating Our First Tool Registering Tools Creating a Tool with Parameters Providing Tools at Invocation Time As we slowly move through our journey of learning Spring AI, there is something important we need to understand. An LLM does not know about your application environment. What does that mean? Think of a simple question like this: "What is the current date and time?" LLMs are trained using data from the past. They do not automatically have access to the current date and time, your database, your APIs, or your application's data. By the end of this article, our AI assistant will be able to use Java methods to access such information and perform actions. Why Tool Calling Exists LLMs are excellent at: Explaining Summarizing Reasoning Generating text And much more However, they cannot directly: Access real-time information Access databases Call application APIs Execute business actions This ...

Spring AI: Conversation Memory

Greetings! Why Do We Need Memory? How Conversation Memory Works Spring AI Chat Memory Why Use a Message Window? Creating a ChatClient with Memory What Is a Memory Advisor? ChatMemory ChatMemoryRepository Memory Advisor Understanding Conversation ID Building a Memory-Enabled Endpoint Chat Memory vs Chat History Summary In our previous articles, we explored various Spring AI capabilities with simple examples. However, there is one important capability missing from our applications. Our AI assistant cannot remember previous conversations. This is expected LLM behavior. A model does not automatically remember previous requests. However, we can make our AI application remember a conversation by providing previous messages as context. This is where conversation memory becomes important. Why Do We Need Memory? Without memory, every request is treated independently because the model has no way to understand the previous conversation. Imagine the following conversation: tex...

Spring AI: Structured Output with Java Records

Greetings! What Is Structured Output? Mapping Responses to Java Records Mapping Collections Wrapper Records vs Collections Externalized Prompts with Structured Output system.st user.st Putting It All Together Summary In previous articles, we used Spring AI to generate responses in text format. While generating text is useful, enterprise applications rarely need only free form responses. Applications usually need predictable data that can be processed by application logic. Imagine we need to extract customer details using an LLM. text Extract customer information: John Smith john@example.com +1 555-1234 The LLM may correctly return a response like this: text Name: John Smith Email: john@example.com Phone: +1 555-1234 While this looks fine to the human eye, our application cannot reliably parse this kind of response. The model may change the format. text Customer Name: John Smith Email Address: john@example.com Contact Number: +1 555-1234 Or it may return a sentence. text...