Blog
What is RAG in AI, and when does your brand need it?
RAG (retrieval-augmented generation) is a technique where, before an AI model answers, a system searches a source of information for the passages that relate to the question and hands them to the model along with it. The model answers from what it just read, instead of relying only on what it learned in training. If the source is your price list, your opening hours and your policies, that is where the answer comes from. The approach was set out in a 2020 paper by Patrick Lewis and colleagues.
An example: the same DM with and without RAG
Fictional example. Lumbre is a coffee roaster that sells on Instagram. On a Saturday, this DM comes in: “How much is a kilo of the Huila, and can you ship it tomorrow?”
- Without RAG. The assistant only has what the model learned and the general instructions it was given. It doesn’t know Lumbre’s price or shipping days. If nobody told it to admit what it doesn’t know, it may reply with a price that sounds reasonable and a cheerful “Sure, it’ll arrive tomorrow!” Both could be false.
- With RAG. Before answering, the system searches Lumbre’s documents and finds two passages: “Huila coffee, 1 kg: USD 24 (price list valid from November 3)” and “We ship Monday to Friday; weekend orders go out on Monday.” The model gets the question, those two passages and an instruction: answer only from these, and if the answer isn’t there, say so. It replies: “A kilo of the Huila is USD 24. We don’t ship on weekends, so if you order today it goes out on Monday.”
- When the answer isn’t there. Someone else asks whether they sell gift cards. No document mentions it. Set up well, the assistant says it doesn’t have that information and leaves the conversation for someone on the team.
Lumbre didn’t retrain any model. If the price goes up on Monday, they change one line in the document, and the next answer already uses the new price.
How RAG works, step by step
Anthropic, the company that develops Claude, describes the usual process in its post on Contextual Retrieval (September 19, 2024). There is a preparation stage and a query stage.
Preparation, once and again whenever the documents change:
- The documents (the “knowledge base”) are split into smaller chunks of text.
- An embedding model turns each chunk into a vector, a list of numbers that represents its meaning.
- Those vectors are stored in a vector database.
Query, every time someone asks something:
- The system finds the chunks closest in meaning to the question.
- It adds the most relevant ones to the prompt the model receives.
- The model generates the answer with that information in front of it.
The same post points out two weak spots that matter for a brand:
- Exact matches. Search by meaning is good at capturing how ideas relate, but it can miss exact matches, such as a product code. That’s why it gets combined with keyword search (BM25, a function that ranks results by matching terms). If your customers ask about a SKU or an exact model name, this matters.
- The chunk that loses its context. When a document is split up, a chunk can lose what made it make sense. Anthropic’s example is a chunk from a financial filing that says “the company’s revenue grew by 3%” without saying which company or which quarter. A price list has the same problem when a line says “USD 24” under a heading that ended up in another chunk. Our suggestion: write each line so it stands on its own, with the product name and size next to the price.
Where it comes from: the 2020 paper
The paper that introduced RAG models is “Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks”, by Patrick Lewis and colleagues, posted to arXiv on May 22, 2020. It starts from an observation: language models store knowledge in their parameters, but they struggle to access it precisely, and showing where an answer came from and updating what they know were, according to the authors, open research problems.
Their proposal combines two memories:
- A parametric one: a pretrained language model, what the model “knows.”
- A non-parametric one: a vector index of Wikipedia, where the system looks up passages.
They tested two variants: one uses the same retrieved passages for the whole answer, and the other can use different passages for different parts of the text. They reported state-of-the-art results on three open-domain question answering tasks, and answers that were more specific, diverse and factual than a comparable model without retrieval.
For a brand, the useful part of that idea is the split: what changes (prices, stock, hours) lives in documents you can edit, and the model handles understanding the question and writing the reply.
Do you need RAG, or is a context document enough?
Often the document is enough. In the same post, Anthropic writes that if your knowledge base is smaller than 200,000 tokens (about 500 pages of material), you can include the whole thing in the prompt you give the model, with no need for RAG or similar methods. It adds that Claude’s prompt caching makes that approach faster and cheaper: according to the company, with latency cut by more than 2x and costs by up to 90%. Once the knowledge base grows past that, you need a solution that scales. That limit is the model’s context window, and what a context window is and what happens when it fills up covers what takes up room in a working conversation.
The 200,000 tokens is the figure Anthropic gave for Claude in September 2024. How much text an assistant accepts depends on the model and the tool: check the one you use before you apply it.
A small brand’s price list, opening hours, returns policy and FAQs usually take up a few pages. For that, a well-written context document that the assistant reads in full in every conversation is simpler to maintain than a search system. This table is our own synthesis:
| Your situation | What’s enough | Why |
|---|---|---|
| Prices, hours, shipping and policies in a few pages | A context document | It fits in the prompt in full, and you update it in one place |
| A catalog of hundreds of products with changing product sheets | RAG | Sending the whole catalog with every message doesn’t make sense; the sheets that relate to the question are enough |
| Manuals, contracts or a help center with hundreds of articles | RAG | It exceeds what fits in the prompt, or makes every query more expensive |
| Data that changes by the minute (stock, order status) | A connection to the system that holds the data | A copied document goes stale; the assistant has to check the source at that moment |
For that last case there are other routes, such as MCP, the open standard that connects an assistant to your tools and data. And when an assistant decides on its own what to look up and what to do next, it is getting close to what’s called an agent: the difference is covered in what an AI agent is and how it differs from a chatbot.
If you want to try the idea of a folder of files your AI reads before it answers, the guide how to create your knowledge layer sets one up with Claude or Codex. It’s designed to store what you tell it about yourself, not a brand’s catalog, but the principle is the same: the AI answers from what’s written in your files.
RAG and hallucinations: it lowers the risk, it doesn’t remove it
A hallucination is text the model generates that is factually incorrect or doesn’t match the information it was given. RAG tackles one of its causes: the model no longer has to “remember” your price, because it reads it. But there are still three ways to get it wrong:
- The search doesn’t bring back the right chunk. In Anthropic’s tests, retrieving the top 20 chunks, the usual method failed to find the relevant information 5.7% of the time. With its best combination (chunks with added context, search by meaning and by keyword, and a final reranking step), the rate dropped to 1.9%. Lower, not zero.
- The document is wrong or out of date. RAG answers with what it finds. If the price list is from March, it gives March’s price with the same confidence.
- The model fills in the gap. If the chunk doesn’t fully answer the question, the model may fill the gap with something plausible.
Anthropic’s guide to reducing hallucinations suggests, among other techniques, explicitly allowing the model to say it doesn’t know, telling it to use only the information in the documents you provide and not its general knowledge, and having it cite the text that supports each claim, retracting any claim it can’t support. The same guide warns that these techniques reduce hallucinations but don’t eliminate them.
What a brand needs to take care of
If an assistant with RAG or a context document is going to reply to your customers, these are the decisions that are up to you (they’re our recommendations, based on the above):
- One version of each fact. If the old and new price lists sit side by side, the search may bring back either. Delete or archive what you replaced, and put the effective date in the document.
- Someone in charge of keeping it current. When a price or opening hours change, have someone update the document that same day. That change is what updates the answers.
- Permission to say “I don’t know.” Write into the instructions what it should reply when the information isn’t there, for example: “I don’t have that information; I’ll pass you to someone on the team.”
- A way to see where the answer came from. The customer doesn’t need a citation, but whoever reviews the replies has to be able to see which chunk was used. That’s how you catch an outdated document before a customer does.
- Sensitive cases go to a person. A complaint, a return outside your policy or a legal question isn’t solved with a passage from your documents.
If you use HeyMark, its AI replies to comments and DMs in your brand’s voice, with approval and handoff to a person: you can review a reply before it goes out and leave sensitive conversations to someone on the team. How that works for Instagram messages is covered in an AI chatbot for Instagram DMs that replies in your brand’s voice.
Plan your next post in HeyMark.
Keep the idea, review the draft with your team, and see how it performed in the accounts you connected.