RAG

Index


Introduction

Retrieval-Augmented Generation (RAG) is a technique that makes Large Language Models (LLMs) smarter and more reliable by giving them access to external information(context) before they answer your questions.

In simpler terms, imagine an LLM as someone with a lot of general knowledge from books they've read (their training data). When you ask them a question, instead of just relying on what they remember, RAG allows them to quickly look up relevant information from other trusted sources, like a specific document or database. They then use this fresh information, along with their existing knowledge, to give you a more accurate and up-to-date answer.

Think of it like this:

  • You ask the LLM a question.
  • The RAG system first retrieves relevant information from external sources based on your question. This is like a quick search.
  • This retrieved information is then added to your original question.
  • The LLM then uses this enhanced prompt to generate a more informed and accurate response.

The main goal of RAG is to improve the accuracy and reliability of LLM responses by grounding them in specific data, which helps to reduce issues like making things up (hallucinations) and ensures the information is more current and relevant. This is especially useful when dealing with information that the LLM wasn't trained on or that changes frequently.

Here are the basic steps involved in Retrieval-Augmented Generation (RAG) techniques, based on the information in the sources:

  1. User enters a prompt/query: The process begins when a user submits a question or prompt to the system. This query is the starting point for the RAG chain.

  2. Information Retrieval: Based on the user's query, the RAG system retrieves relevant data from an external knowledge base or the organisation's internal sources. This retrieval step functions like a search engine, sifting through a collection of documents to identify the most relevant information. Techniques like semantic search (embedded in vector databases) are often used to understand the meaning behind the query.

  3. Prompt Augmentation: Once relevant information is retrieved, the RAG system combines (or merges) it with the original user prompt. This creates an enhanced or augmented prompt that includes both the user's intent and the additional contextual knowledge from the retrieved data. This step might involve prompt engineering techniques to communicate effectively with the LLM.

  4. Response Generation: The augmented prompt is then fed into the Large Language Model (LLM). The LLM uses this new knowledge, along with its pre-existing training data, to generate a more accurate, informed, and contextually relevant response.

Basic RAG

Pros and Cons of RAG

RAG Pros & COns