What is retrieval-augmented generation and why use it for LLMs?

How RAG lets an LLM answer from your own documents and current web pages, and cite where each answer came from.

A customer asks your shop’s AI assistant, “I bought a lamp on clearance two weeks ago, but I’ve changed my mind. Can I return it?”

Your shop accepts returns within 30 days, but it doesn’t accept clearance returns when a customer simply changes their mind. If the assistant finds only the 30-day rule, it might say yes. The customer could then travel to the shop expecting a refund they can’t get.

To answer correctly, the assistant needs to find the clearance exception as well as the general rule. Retrieval-augmented generation, or RAG, helps it find and use both before answering.

What is RAG?

Retrieval-augmented generation (RAG) is a method that helps an AI model answer questions using information retrieved from documents, websites, or databases. The application searches these sources for relevant content and passes it to the model along with the question.

For example, a model may understand how returns generally work from its training without knowing your shop’s returns policy. With RAG, the application retrieves, attaches, and passes your policy details directly to the model, which then uses that information to answer queries.

How does RAG work?

Your AI assistant may need only a few paragraphs from a long document to answer a question. To make those passages easier to find, RAG splits documents from knowledge base software and other sources into smaller sections called chunks. When someone asks a question, the application retrieves the most relevant chunks and sends them to the model.

Here’s how the process works in three steps:

  1. Retrieval: Finds sections that help answer the question or provide more context. For the clearance lamp, the assistant needs to find both the 30-day return policy and the exception rule.
  2. Augmentation: Adds those sections to the question and sends them to the LLM. The input can include instructions for the model on how to use the sourced data.
  3. Generation: Writes an informed answer using the information provided. The assistant can easily cite the sources it used or even say when it lacks enough information to answer.

Why use RAG for LLMs?

Without access to current web data, online policies, product details, or internal guides, your LLM can give an answer that sounds convincing but is wrong for your customer or employee. RAG helps it find and use information that applies directly to the user’s situation.

And if your policies and internal guides are scattered across files, you can create a knowledge base to organize them in one place for easier searching.

Keeping those answers current is the next challenge. When web content or product details change, RAG lets you update your search system with the new information without retraining the LLM. Those changes must be indexed correctly, though, or your assistant might keep using the older copy.

Also, your customers or staff might want to see where an answer came from before trusting it. RAG lets your assistant link to the web pages and documents it uses to answer, allowing them to check the details themselves. If something looks wrong, they can follow those links to investigate further.

Keep your AI informed with Apify’s RAG Web Browser

Web content can change while your assistant keeps answering from an outdated source, but you don’t need to build a RAG pipeline from scratch to feed your LLMs current data.

Apify’s RAG Web Browser fetches pages from URLs or Google search queries and returns readable text alongside the source links. Your model just reads the updated text directly and cites the original sources.

Say your team is setting up a free Slack workspace, and you want to know how far back you can search messages and how many apps you can install. Both limits are on Slack’s Usage limits for free workspaces page.

Instead of extracting, downloading, and indexing this entire page while maintaining a database for it just to implement RAG, here’s a simpler alternative:

  1. Open RAG Web Browser, click Try for free, and sign in or create an Apify account.
  2. In the Input form, paste this URL into Search term or URL:
https://slack.com/help/articles/115002422943-Usage-limits-for-free-workspaces
  1. Leave Markdown selected under Output formats and click Start.
  2. When the run concludes, open Output. Copy the page text from markdown and the source URL from metadata.url.
  3. Paste this prompt into your AI assistant, followed by the page text and source URL:
Using only the web content below, answer these questions: How far back can my team search messages on Slack’s free plan? How many third-party or custom apps can we install? Cite the source URL. If the page doesn’t answer either question, say what’s missing.

The same question was tested in two fresh assistant runs, with and without excerpts fetched by RAG Web Browser. Here are their responses:

Without retrieved web content With content from RAG Web Browser
“Slack’s free plan allows the most recent 90 days of messages and up to 10 third-party or custom apps. These are the limits I know; I haven’t verified whether Slack has changed them recently.” “On Slack’s free plan, your team can search messages from the last 90 days and install up to 10 third-party or custom apps total.” Includes a link to Slack’s free-workspace limits.

Both answers gave the correct limits. Fetching Slack’s page gave the second assistant a current source to cite, so readers can check the answer against Slack’s documentation.

To automate this process, connect RAG Web Browser directly to your AI agent through its APIs or the Apify MCP server.

The limitations of RAG

Giving your assistant access to information doesn’t guarantee a correct answer. It can still miss an important detail, use an outdated source, or reveal information the user shouldn’t see.

The table shows what you can do about each problem:

When… How to address it
The search misses an important detail Have it search for the missing conditions before answering. If it still can’t find them, it should explain what information is missing.
Your documents have different versions Record when each version took effect. Use those dates to select the version that applies to the question.
Some documents are private Identify who is asking and restrict the search to documents they can access, before sending any text to the model.

You don’t need to use the same approach for every question. Your assistant can use RAG to find and explain information from documents and a conversational analytics tool to calculate totals from business records. The right approach depends on the question.

On this page

Don't build it. Find it.

Thousands of ready-to-run tools for AI.

Browse Apify Store