Text-to-SQL, Spring AI Implementation with RAG
Building AI applications is very popular these days. For Java developers, the best choice for building AI applications is using Spring AI. To learn how to use Spring AI to build AI applications, we need to have a concrete example. Text-to-SQL is a typical usage of using AI to improve productivity. By using Text-to-SQL, non-technical people use natural language to describe database query requirements. These queries are sent to LLM. LLM can generate SQL statements to answer user queries. LLM can also use tools to execute SQL statements, and return the query results to the user. Text-to-SQL is a good example of AI applications.
Below is the architecture diagram of the sample application.
In this course, we will use Spring AI to create a text to SQL application. After learning this course, you will know:
- How to use ChatClient to send requests to LLM and receive responses.
- How to extract database metadata and include them in the prompt sent to LLM.
- How to use Spring AI advisors to intercept
ChatClient
requests to process requests and responses. - How to use embedding model and vector store to implement semantic search of database metadata.
- How to use LLM to generate summary of database tables and SQL statements.
- How to use LLM to re-select tables automatically.
- How to allow user to manually re-select tables using message history.
- How to execute and validate SQL statements using functions.
- How to deployment metadata indexer and Text-to-SQL application as serverless functions on AWS Lambda.
- How to build web UI using assistant-ui to interact with backend API.
- How to use Spring Cloud Function to deploy Text-to-SQL application and metadata indexer as serverless functions and run them on AWS Lambda.
This course covers all major aspects of Spring AI, including ChatClient
, advisors, embedding models, vector stores, chat
memory and function calling.
What you have learned in this course, can help you build other AI applications using Spring AI.
This course provides full source code of a complete Text-to-SQL application. This application is deployed to AWS Lambda as a serverless function.
Below are screenshots for the web UI.