Skip to main content

RAG intro

, 2 min read

Ever wondered how some AI systems seem to know exactly what you need? They might be using a technique called retrieval-augmented generation (RAG). It's like giving the AI a little research assistant:

  1. When you ask a question, the AI first looks for relevant information in its own knowledge base or in external sources.
  2. It combines what it found with your question to create a detailed prompt.
  3. It uses a powerful language model to generate a response that's both informed and tailored to your needs.

RAG definition​

In its most basic form, a RAG application runs three steps:

  • Retrieval: The user's request is used to query an outside source of information. This might mean querying a vector store, running a keyword search over some text, or querying a SQL database. The goal of the retrieval step is to obtain supporting data that helps the LLM provide a useful response.
  • Augmentation: The supporting data from the retrieval step is combined with the user's request, often using a template with additional formatting and instructions for the LLM, to create a prompt.
  • Generation: The resulting prompt is passed to the LLM, which generates a response to the user's request.
User request ──► Retrieval ──► Augmentation (request + supporting data) ──► Generation ──► Response