By Shiwen Ji
Retrieval Augmented Generation (RAG) is a technique for integrating data with artificial intelligence models. In the RAG workflow, the first step is to load the document data into a vector database, such as Redis. When receiving a user query, the vector database retrieves a set of documents similar to the query. This document data then serves as the context for the user's question and is used in conjunction with the user's query to generate a response (typically through the LLM).
In this example, we will use a dataset that contains information about the beers, including attributes such as name, alcohol volume (ABV), and international bitterness unit (IBU), and a description of each beer. The dataset is loaded into Redis and builds a Spring project with Spring Cloud Alibaba AI Starter to demonstrate the workflow of the RAG application.
Vector databases often act as memory for artificial intelligence applications. This is especially the case for those supported by the large language model (LLM). Vector databases allow semantic search, which provides relevant context for LLM. The Spring AI project aims to simplify the development of artificial intelligence-driven applications, including the application of vector databases.
You can find the link to this sample source code in the official SCA blog: sca.aliyun.com
This example uses Spring Cloud Alibaba AI and Spring AI Redis and builds a Web application with Spring Web.
The data used by RAG applications consists of JSON documents. The content of the documents is as follows:
{
"id": "00gkb9",
"name": "Smoked Porter Ale",
"description": "The Porter Pounder Smoked Porter is a dark rich flavored ale that is made with 5 malts that include smoked and chocolate roasted malts. It has coffee and mocha notes that create a long finish that ends clean with the use of just a bit of dry hopping",
"abv": 8,
"ibu": 36
}
In this example, we insert data into Redis with the RagDataLoader class.
When RAGService class is prompted by the user, it calls the retrieval method and performs the following steps:
You can get the output of the RAG application by calling the Web API through the browser or the curl command. Default prompt parameter: What beer pairs well with smoked meats?
curl $ curl http://127.0.0.1:8081/rag/chat
# If everything goes well, you will see the response as follows:
Bieré De Ménage would pair well with smoked meats due to its high ABV (8%) and potentially the influence of oak barrels from the winemaking process, which can complement the rich flavors of smoked dishes. However, if you prefer a sturdier stout, Son of Berserker Stout with its 6.9% ABV and 20 IBUs could also serve as a good match for smoked foods, especially since it's a substantial stout without additional complexities like bourbon or oak.
If you use the browser to call, you will see the content as follows:
In this example, Spring Cloud Alibaba AI is stored with Redis vector, and the RAG application is implemented through only a few classes. Welcome to try Spring Cloud Alibaba AI Starter. If you have any questions, please contact us through Issue.
Evaluating Next-Generation Log Processing: iLogtail SPL vs. Logstash
494 posts | 48 followers
FollowAlibaba Cloud Native Community - July 18, 2024
Alibaba Cloud Data Intelligence - June 20, 2024
Farruh - February 26, 2024
ApsaraDB - May 15, 2024
Farruh - July 18, 2024
Alibaba Cloud Community - September 6, 2024
494 posts | 48 followers
FollowOffline SDKs for visual production, such as image segmentation, video segmentation, and character recognition, based on deep learning technologies developed by Alibaba Cloud.
Learn MoreAccelerate and secure the development, deployment, and management of containerized applications cost-effectively.
Learn MoreAccelerate AI-driven business and AI model training and inference with Alibaba Cloud GPU technology
Learn MoreTop-performance foundation models from Alibaba Cloud
Learn MoreMore Posts by Alibaba Cloud Native Community