RAG (retrieval-augmented generation) is a technique in which an application retrieves relevant documents from its own data and adds them to an LLM's prompt before the model answers. The model then answers from that context instead of only from its training data, which keeps answers current and lets them cite sources.

Learn ChatGPT & LLMs from these channels

  1. Intellipaat 13.4M subscribers · 6 videos on ChatGPT & LLMs in our index
  2. freeCodeCamp.org 12M subscribers · 10 videos on ChatGPT & LLMs in our index
  3. CodeWithHarry 10M subscribers · 3 videos on ChatGPT & LLMs in our index
  4. Simplilearn 6.8M subscribers · 50 videos on ChatGPT & LLMs in our index
  5. NetworkChuck 5.5M subscribers · 5 videos on ChatGPT & LLMs in our index

See all ChatGPT & LLMs channels →

How RAG Works

The RAG pipeline: (1) User asks a question. (2) Your system converts the question to an embedding vector. (3) It searches a vector database for similar documents. (4) The retrieved documents are added to the LLM prompt as context. (5) The LLM generates an answer grounded in that context.

RAG is how you build AI that knows about YOUR data — company docs, product manuals, codebases — without expensive fine-tuning. Tools like LangChain, LlamaIndex, and Vercel AI SDK make building RAG pipelines straightforward.

Why Developers Use RAG

RAG powers custom knowledge chatbots, documentation search, customer support bots, and internal tools. It's the #1 pattern for building AI applications on proprietary data because it's cheaper and more flexible than fine-tuning.

Key Concepts

  • Vector Search — Finding similar documents by comparing embedding vectors using cosine similarity or dot product
  • Chunking — Splitting documents into smaller pieces (500-1000 tokens) for more precise retrieval
  • Context Window — RAG is limited by the LLM's context window — you can only inject so many retrieved documents
  • Hybrid Search — Combining vector (semantic) search with keyword (BM25) search for better retrieval accuracy

Learn RAG — Top Videos

Frequently Asked Questions

What is RAG used for?

RAG is used for chatbots over company documents, customer support assistants, search over internal knowledge bases and coding assistants that read a codebase. A typical pipeline splits documents into chunks, stores their embeddings in a vector database, retrieves the closest chunks for each question and passes them to the model.

What is the difference between RAG and fine-tuning?

RAG retrieves relevant context at query time. Fine-tuning modifies the model's weights on your data. RAG is cheaper, faster to set up, and handles dynamic data. Fine-tuning is better for changing the model's style or behavior.

What tools do I need for RAG?

An embedding model (OpenAI, Cohere), a vector database (Pinecone, Weaviate, Cloudflare Vectorize), and an LLM API. Frameworks like LangChain or LlamaIndex tie them together.