DEV Community

Cover image for My journey exploring to presentation about RAG - Retrieval Augmented Generation
Kamalesh AR
Kamalesh AR

Posted on

My journey exploring to presentation about RAG - Retrieval Augmented Generation

Recently, I had the opportunity to deliver a presentation on Retrieval-Augmented Generation (RAG) at my institute. Preparing for this session helped me understand not only what RAG is, but also why it has become one of the most important techniques in modern AI applications.

In this blog, I'd like to share what I learned and explain RAG in a simple way.

What is RAG:

Retrieval-Augmented Generation (RAG) is the process of optimizing the output of a large language model, so it references an authoritative knowledge base outside of its training data sources before generating a response.

  • Retrieval: Search for relevant information from documents, databases, or websites.
  • Augmentation: Add the retrieved information to the user's question as additional context.
  • Generation: The LLM uses both the question and the retrieved information to generate an accurate answer.

Large Language Models (LLMs) are trained on vast volumes of data and use billions of parameters to generate original output for tasks like answering questions, translating languages, and completing sentences.

RAG extends the already powerful capabilities of LLMs to specific domains or an organization's internal knowledge base, all without the need to retrain the model. It is a cost-effective approach to improving LLM output so it remains relevant, accurate, and useful in various contexts.

Example

"What is my college's attendance policy?"

Without RAG

The AI only uses its training knowledge and might answer:

"Most colleges require around 75% attendance."

This is a generic answer and may not be correct for your college.

With RAG

The AI first searches your college handbook, retrieves the attendance policy, and then answers:

"According to your college handbook, students must maintain at least 80% attendance."

Why RAG:

LLMs are a key artificial intelligence (AI) technology powering intelligent chatbots and other natural language processing (NLP) applications.

The goal is to create bots that can answer user questions in various contexts by cross-referencing authoritative knowledge sources.

Unfortunately, the nature of LLM technology introduces unpredictability in LLM responses. Additionally, LLM training data is static and introduces a cut-off date on the knowledge it has.

Known challenges included:

  1. Presenting false information when it does not have the answer.
  2. Presenting out-of-date or generic information when the user expects a specific, current response.
  3. Creating a response from non-authoritative sources.
  4. Creating inaccurate responses due to terminology confusion, wherein different training sources use the same terminology to talk about different things.

Working:

  1. Query Processing: The input query is first pre-processed and prepared for further steps, ensuring it is in a suitable form for embedding.
  2. Embedding Model: The query is passed through an embedding model that converts it into a vector capturing its semantic meaning.
  3. Vector Database Retrieval: This vector is used to search a vector database to find documents that are most similar to the query.
  4. Retrieved Contexts: The system retrieves the documents that are closest to the query. These documents are then forwarded to the generative model to help it craft a response.
  5. LLM Response Generation: The LLM combines the original query with the retrieved context to generate a coherent and accurate response.
  6. Response: The final response integrates both the modelโ€™s internal knowledge and the retrieved information, making it more relevant and up-to-date.

Three pillars of RAG:

Popular RAG Tools:

LLM's:

  • Chatgpt
  • Claude
  • Gemini
  • Llama

Vector Databases:

  • FAISS
  • Pinecone
  • ChromaDB
  • Milvus

Frameworks:

  • LangChain
  • LlamaIndex
  • Haystack

Embedding Models:

  • OpenAI Embeddings
  • BGE
  • E5
  • Sentence Transformers

Purpose:

The purpose of a Retrieval-Augmented Generation (RAG) model is to improve the accuracy and relevance of AI responses by pulling facts from external knowledge bases rather than relying solely on its static training data.

1. Grounding in Factuality

The primary purpose of RAG is to anchor Large Language Models in verified, authoritative source material. By feeding the exact context along with the query, RAG dramatically reduces hallucinations and equips the system to cite sources transparently.

2. Dynamic Data Integration

Instead of relying on a static knowledge window frozen during pre-training, RAG dynamically pulls live enterprise data, inventory lists, internal wikis, or real-time APIs. This ensures answers are always current without requiring costly, slow model retraining cycles.

Top comments (0)