Skip to main content

Text-to-SQL Course Update (Spring AI 1.0.0)

· 3 min read

In this post, I'll talk about changes made to the implementation of Text-to-SQL course. The source code has been updated to Spring AI 1.0.0 release version.

Compared to previous milestone versions, there are some major changes in 1.0.0.

Module Names

Module names have been changed to follow certain naming patterns. The module spring-ai-core is removed. ChatClient is now put into the module spring-ai-client-chat.

Spring boot starter modules have the same name prefix spring-ai-starter. Starters for AI models have the name prefix spring-ai-starter-model, while starters for vector stores have the name prefix spring-ai-starter-vector-store.

Advisor

The design of advisor has been finalized. Advisors no longer use dedicated classes for requests and responses.

In the previous implementation, AdvisedRequest is used to represent requests, passed between the advisors chain. This AdvisedRequest is finally converted to the Prompt used by ChatClient. In the current implementation, ChatClientRequest is used. ChatClientRequest is a wrapper of a Prompt and a context map. This means advisors now directly modify Prompts.

public record ChatClientRequest(
Prompt prompt,
Map<String, Object> context) {}

This change is also applied to responses. ChatClientResponse replaces AdvisedResponse. ChatClientResponse is a wrapper of a ChatResponse and a context map.

public record ChatClientResponse(
@Nullable ChatResponse chatResponse,
Map<String, Object> context) {}

To update a ChatClientRequest or a ChatClientResponse, we can call the mutate method to get a builder object, then use methods of the builder to update it, and finally call the build method to get a new object.

Chat Memory

The support for chat memory has also been updated. ChatMemoryRepository is the new interface to manage storage of chat messages. You can choose to use in memory storage, or persistent storage with RDMBS, Neo4j, or Cassandra.

ChatMemory is used by application to manage messages. ChatMemory delegates the actual storage to ChatMemoryRepository, but offers various strategies to use messages. The built-in MessageWindowChatMemory uses a fixed sliding window to select recent messages.

MessageChatMemoryAdvisors can now only be created using builders. ChatMemory.CONVERSATION_ID should be used to set the parameter for conversation id.

Tools

For tools, Spring AI no longer uses the term function, but always uses tool.

A new annotation Tool can be used to describe tools. This annotation can be added to a method to register it as a tool. We can specify the name and description of this tool.

That's all for the updates. The source code has been updated. You can get a copy of the source code from the fifth lecture.