Skip to main content
All posts

What is retrieval-augmented generation (RAG) and how does it work?

What is retrieval-augmented generation? See how AI search finds the right content, then writes a sourced answer from it, and how RAG differs from search.

sorchy team

5 min read

Retrieval-augmented generation (RAG) is a way for an AI system to answer a question using information it looks up. First, the search system finds a relevant passage, such as a rule in a store’s returns policy. Then a language model uses that passage to write the answer.

Suppose a shopper asks a retailer’s help center, “Can I return an online gift to a store?” A list of links might get them to the right policy. A direct answer can tell them whether it’s worth making the trip, how long they have, and what to bring. A link to the relevant passage lets them check those details before they leave home.

What is retrieval-augmented generation?

The word “retrieval” refers to finding information, such as a paragraph in a help article. “Augmented” means adding that information to what the model receives alongside the question. “Generation” is the step where the model writes a response. The passages it can consult while writing are part of its context.

Think of a support representative checking the handbook before answering a customer. The representative may know how returns usually work. What matters here is whether this retailer accepts this type of return. Giving the model the applicable policy serves much the same purpose. You don’t need to retrain the model every time the retailer changes the return window.

What does RAG add to an AI answer?

A model can explain what a gift receipt is without knowing how a particular business handles one. It might give a plausible answer based on common practice, even if that answer conflicts with your policy. Retrieval gives it the passage your support team would rely on to answer the same question.

This distinction matters when an answer sounds right but isn’t. If the system finds the policy for regular purchases instead of gifts, the search step needs attention. If it finds the gift policy but leaves out the receipt requirement, the problem lies in how the answer uses the evidence.

How AI search answers a question in five steps

Let’s follow the shopper’s question through a fictional retailer’s help center. The five steps below illustrate one common design. Some systems skip a separate ranking step, and some show source links instead of numbered citations. In each case, you can ask the same question: did the model receive the information it needed to answer accurately?

1. Make the question clear enough to search

Suppose the shopper first asks, “How do I return a gift I got online?” Their next question is, “Can I bring it to a store?” Taken alone, “it” could refer to almost anything. A system that uses the conversation history can search for “return an online gift to a store,” keeping both useful details: it was a gift, and it was bought online.

Rewriting the query shouldn’t introduce details the shopper never gave. If the conversation only says “Can I return it?” and different policies apply to gifts and personal purchases, asking “Was it a gift?” may be more useful than guessing and retrieving the wrong policy.

2. Find relevant content

The search system looks through the sources it’s allowed to use. For a public help center, those might include the returns policy, store information, and instructions for starting a return. These pages may already be in a searchable index. The system doesn’t need to search the entire web each time someone asks a question.

The shopper says “bring it to a store,” while the policy says “in-person returns.” A meaning-based search can help connect the two. One way to do that is to represent queries and passages numerically and compare them. Our guide to vector databases explains how those representations can be stored and searched. A dedicated vector database isn’t a requirement for every RAG system.

3. Select the passages that answer this question

A store locator, a return label form, and the gift policy could all appear in the results. Only one may say whether a gift purchased online can be returned in person. Hybrid search can combine exact terms, such as a policy or product name, with matches based on meaning. A system can then rank the results again and send the most useful passages to the model. A short section containing the rule and its exceptions can be more useful than a whole help article.

4. Write an answer that keeps the conditions intact

Suppose the sample policy reads, “Gifts purchased online can be returned at any store within 30 days of delivery. Bring your gift receipt.” The source gives the model enough information to tell the shopper what to do:

“Yes. You can return the gift at any store within 30 days of delivery. Bring your gift receipt. [1]”

“Yes, you can return it” leaves out two details that could determine whether the trip is worthwhile. An answer that says “30 days from purchase” would change the rule altogether. The distinction between purchase and delivery is small on the page and significant for someone approaching the deadline.

Now suppose the shopper asks, “If I mail it back instead, who pays for shipping?” The sample passage doesn’t say. Unless another current source covers return shipping, a useful answer should say that the available policy doesn’t specify who pays. Silence about shipping is no basis for promising a prepaid label.

5. Show where the answer came from

In this example, [1] stands for a link to the gift returns section of the policy. In a working help center, the shopper should be able to open that link and find the sentence the answer relies on. Sending them to the help center homepage would leave them with the same search they started with.

Sometimes a response combines information from several pages. The returns policy might establish eligibility, while a store page lists opening hours. Put each source next to the claim it supports so the shopper can check the part that matters to them.

Which sources should a RAG system use?

Start with the material your team trusts to settle the question. That might be a policy page, a product manual, or a table of service limits. Preserve the context that gives a passage its meaning. A fee in a table, for instance, says little if the search system drops the column heading that identifies the plan it applies to.

Some questions depend on a current record. “Has my refund been issued?” can’t be answered from a general policy. Answering from live data requires access to the relevant system and permission to retrieve that customer’s record. Access to the public help center doesn’t grant access to an individual order.

Classic search vs. generative AI search

Classic site search ranks pages or documents for the visitor to explore. Generative AI search can use retrieved passages to write an answer as well. The two can share an interface. A visitor might read the answer, check its source, or browse the rest of the results.

Visitor’s taskClassic searchGenerative AI search
Find an answerShows relevant pages and documents.Can give a direct answer based on the retrieved material.
Get something doneA direct link opens a form or policy.A short explanation can clarify which steps or conditions apply.
Check the resultOpen the page and find the rule.Follow the citation and compare the answer with the actual rule.

For a query like “return label,” the most helpful result may be a link that opens the form. A paragraph about return labels only gets in the way. For “Do I need a return label if I take the gift to a store?” a direct answer can save the shopper from printing something they may not need. But the system still needs a source that addresses the label requirement. A policy that mentions only a gift receipt doesn’t settle the question.

Why a RAG answer can still be wrong

A recent policy change won’t help if the search index still contains the old version. Check which version the system actually retrieved, especially if two pages with similar titles give different instructions. Asking the model to pick the newer rule won’t resolve a conflict when neither page identifies which rule is in effect.

A second failure can happen when a document is split into passages. The return window might appear in one paragraph and an exception for clearance items in the next. If retrieval supplies only the first paragraph, the model never sees the exception. Keeping the heading and exception together, or retrieving the neighboring passage, can help.

Even with the right passage, a model may add an unsupported detail. AI hallucinations can be hard to spot when the answer is fluent and a citation appears beside it. Open the citation and check the specific claim. If the answer promises free return shipping, the source needs to say who pays.

How to test a RAG answer on your own site

Pick questions visitors actually ask. For each one, write down the expected answer and the sentence that supports it. Include a straightforward policy question, a follow-up that depends on the conversation, and one that your published material doesn’t answer. For that last case, agree on what the system can say without guessing.

Review the retrieved passage before you judge the wording. Did the system find the current gift policy, or did it find a similar rule for purchases made in a store? Then check the answer against the passage. Did it preserve the receipt requirement? Did it count the 30 days from delivery? Those checks tell you whether to fix retrieval, revise the source, or change how the model uses it.

Sorchy’s website chatbot shows numbered sources with its answers. Try asking a question your help center covers, then open the cited passage and compare it with the reply. To see how Sorchy selects that passage, follow what happens when someone asks a question. If your visitors ask questions in your own app, you can also offer source-backed answers with the Sorchy API.

Frequently asked questions about retrieval-augmented generation

How is RAG different from fine-tuning?

RAG supplies information when a question is asked. Fine-tuning changes a model’s parameters by training it on examples. If your support policy changes regularly, retrieval gives the model a way to consult the current version. If you want it to follow a particular response format consistently, fine-tuning may help. The two approaches can be used together.

Do I need to publish private documents on the web?

No. A system can retrieve material from a private knowledge base. Retrieval must respect each person’s access permissions. Hiding the source link is insufficient. Someone who isn’t allowed to read a document shouldn’t learn its contents through a generated answer either.

Can RAG answer questions in other languages?

Yes, if the search system can find relevant passages for queries in those languages and the model can answer in them. Test the wording your audience uses. For example, “Can I bring a gift back to the store?” and “Can I return a gift in person?” should lead to the same conditions. For a multilingual site, repeat that check with natural questions in each supported language, including follow-ups.

Written by sorchy team

Product updates, practical guides and how sorchy works under the hood.

More from the blog

All posts

Let your site answer for itself

Add your site, wait for the index, paste one line of code.