Skip to main content
Practice

The Perfect Combination of Retrieval and Generation: Retrieval Augmented Generation (RAG)

Retrieval Augmented Generation (RAG) is a method where information is retrieved from sources outside the AI model (such as relevant websites, databases, etc.) to generate more accurate responses. It is abbreviated as RAG.

For example, if a user asks, "What's the weather in New York today?" a RAG system retrieves the latest weather information from a weather website or external database and provides an accurate weather update.

Initially, ChatGPT was unable to reference external data for generating responses. However, with current retrieval augmented generation techniques, it minimizes Hallucination and delivers more accurate answers by utilizing external information.

RAG combines the strengths of traditional search engines and generative AI, garnering significant attention as a next-generation search method.


How does RAG work?

RAG systems primarily consist of a Retriever and a Generator.


1) Retriever:

The retriever searches for information related to the question from databases or the internet.

For example, when a user asks, "What's the weather in New York today?" the retriever searches for the latest New York weather information from weather data websites or databases.


2) Generator:

The generator creates the final response based on the retrieved information.

Using the latest New York weather information found by the retriever, it generates a specific and complete sentence like, "Today in New York, it's sunny with a high of 77°F and a low of 64°F."


RAG Process

  1. Question Input: The user inputs a question.

    • Example: "Which city is hosting the 2024 Olympics?"
  2. Information Retrieval: The retriever searches for information related to the question from its own database or the internet.

    • Example: The retriever searches the latest news regarding "2024 Olympics host city."
  3. Information Integration: The retrieved information is passed to the generator.

    • Example: The retrieved information includes the fact "The 2024 Olympics will be held in Paris, France."
  4. Response Generation: The generator creates a response to the question based on the provided information.

    • Example: The generator produces the response, "The 2024 Summer Olympics are scheduled to take place in Paris, France."

What are the advantages of RAG?

While generative AI generates answers based on pre-trained information, limiting the recency of information, RAG provides more accurate and reliable answers by generating responses based on the latest information.

For instance, if a user asks, "What is the latest iPhone model?" RAG searches for the latest news and answers, "The latest iPhone model is the iPhone XY."


How can RAG be utilized?


1. Customer Service

Chatbots can quickly and accurately respond to customer inquiries by providing up-to-date information.

For example, if a user asks, "What is the return policy for this product?" the chatbot searches for the current return policy of the product and provides accurate information.


2. Creation of Summarized Content with Fresh Information

By using RAG, one can search for the latest information and create new content based on it.

For example, in response to a user's query about "Today's news," it searches for the latest news and generates a summarized article.


Major RAG Services

As of 2024, not only existing generative AI services like ChatGPT and Claude but also specialized RAG services like Perplexity are gaining significant public attention.

To utilize RAG with ChatGPT, you can add requests like Refer to search results for your answer or Consider related web documents in the prompt to guide the AI to reference external information when generating responses.


Note

OpenAI does not yet support RAG for external services like Codefriends.

Therefore, in practice environments, you cannot explore external web documents starting with https://.

Thus, practical RAG exercises should be conducted on ChatGPT.

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.