Skip to contentTalk to us
AI fundamentals

RAG explained: answers grounded in your own data

How retrieval-augmented generation (RAG) works step by step, when to choose it over fine-tuning, a worked clinic example, and pitfalls with Arabic content.

Fanann Team10 min read
WhatsApp
Quick answer

RAG (retrieval-augmented generation) means your app first searches your documents for passages related to the user's question, then sends those passages to the language model along with the question so it writes an answer based on them. The model answers from your current data instead of its general memory, which reduces hallucinations and lets it cite sources. It is usually the right choice for FAQs, policies and catalogs, while fine-tuning suits teaching a model a consistent style or format.

People look for this as
  • what is rag in ai
  • retrieval augmented generation explained
  • chatbot that answers from my documents
  • rag vs fine tuning

The problem RAG solves

Ask a general-purpose model, how much is a teeth cleaning at your clinic?, and it has two bad options: apologize because it doesn't know your clinic, or invent a plausible-looking number. As we covered in LLM basics, a model is great with language but knows nothing about your business, and its general knowledge stops at its training date.

The obvious fix is to paste all your documents into the instructions. That runs into context window limits, raises the cost of every message and distracts the model. Enter RAG (retrieval-augmented generation): instead of giving the model everything, you give it only the few passages relevant to each question.

Don't ask the model to remember your business. Have your app open the right file for it at the right moment.

The result is an assistant that answers from your current policies and prices, can name the document it relied on, and clearly says I don't know when it finds nothing. This is called grounding: tying an answer to a source you can verify.

How RAG works, step by step

RAG has two phases: a preparation phase that runs once (and again whenever documents change), and an answering phase that runs with every question.

Preparation (indexing)

  1. 1
    Collect documents

    FAQ pages, policies, price lists, user guides and product pages. Clean out duplicates and outdated information.

  2. 2
    Split them into chunks

    Each document is cut into small, coherent chunks, such as a paragraph or a question with its answer. A good chunk carries one complete idea that makes sense on its own.

  3. 3
    Turn chunks into embeddings

    Each chunk passes through an embedding model that converts it into a list of numbers representing its meaning. Chunks with similar meaning get similar numbers, even when the wording differs.

  4. 4
    Store them in a vector database

    Embeddings are saved with the chunk text and its source in a vector database, which supports searching by meaning, not just keywords.

Answering (every question)

  1. 1
    Embed the question

    The user's question goes through the same embedding model so it lives in the same space as the chunks.

  2. 2
    Retrieve the closest matches

    The app finds the few chunks closest in meaning to the question, often combined with a classic keyword search.

  3. 3
    Build the request

    The app combines the system instructions, the retrieved chunks and the user's question into a single request.

  4. 4
    Generate and cite

    The model writes an answer based only on the chunks and points to the source, or apologizes if the information isn't enough.

RAG, fine-tuning or just a longer prompt?

Before building, ask what the model is actually missing. Is it knowledge (facts about your business) or behavior (a style, a format, a way of classifying)? The answer picks the tool.

CriterionLong promptRAGFine-tuning
Best forSmall, stable informationLarge or changing knowledgeRepeated style or format
Updating informationEdit the text directlyUpdate the document and re-indexRequires retraining
Citing sourcesAwkwardNatural and easyUsually not possible
Starting effortVery lowModerateHigher, needs structured training data
How size affects costGrows with every messageBounded by retrieved chunksTraining cost, then running cost
Choose RAG when
  • Prices, policies or stock change often
  • You have more documents than fit in the instructions
  • You need to cite sources to build trust
  • You want control over what the assistant knows and doesn't
Consider fine-tuning when
  • You want a consistent writing style in your brand voice
  • You need a very specific output format, repeatedly
  • You have many clean examples of the desired behavior
  • Good instructions and a few in-prompt examples weren't enough

An example makes the difference clear: a clothing store in Kuwait wants an assistant that writes in its playful brand voice and knows current sizes and the exchange policy. The voice is stable behavior, usually achievable with good instructions and a few examples. Sizes and policies are knowledge that changes weekly, so they belong in RAG or a direct database lookup. Fine-tuning the sizes into the model would mean retraining with every new shipment.

Worked example: a dental clinic FAQ assistant

Take a dental clinic in Riyadh with two branches that gets the same questions every day on WhatsApp and its website: hours, approximate prices, insurance, pre-visit preparation and parking. The goal is an assistant that answers these accurately, books appointments and routes any medical question to a staff member. See our clinic use cases for more ideas.

SourceWhat it containsChunking note
FAQOpening hours, parking, languages spokenEach question and answer is its own chunk
Services listCleaning, whitening, braces, with general descriptionsOne chunk per service, including branch name
Insurance policyAccepted providers and approval stepsOne chunk per provider or step
Pre-visit instructionsFasting, medication, arrival timeOne chunk per procedure type
  1. 1
    Define the scope

    The assistant handles administrative and general information only. It never diagnoses or prescribes.

  2. 2
    Prepare the sources

    Review each document with the clinic manager, remove outdated prices and add a last-updated date to every file.

  3. 3
    Keep live numbers separate

    Available slots come straight from the booking system, not from a static document that may be stale.

  4. 4
    Write strict instructions

    Answer only from the provided chunks, cite the source, and route medical questions to staff.

  5. 5
    Test and launch

    Thirty real questions from the WhatsApp history, then a pilot on the website before WhatsApp.

A ready prompt to paste into Fanann

Build an AI assistant for a two-branch dental clinic in Riyadh that answers in Arabic and English about FAQs, services, insurance and pre-visit instructions, using only the documents I upload, and names the document it used in every answer. If it can't find the answer or the question is diagnostic, it apologizes politely and offers to hand over to reception. Add appointment booking with phone-number sign-in, and an admin dashboard where I upload and update documents and see the questions it couldn't answer.

Try it in Fanann

Preparing your data: half the work happens before any code

Most RAG problems aren't in the model; they're in the documents. An assistant reading contradictory files will give contradictory answers, however strong the model is.

  • One source of truth: if your return policy appears in three places with three wordings, keep one and delete the rest.
  • Right-sized chunks: too small loses context, too large mixes topics. A question and answer, or a single paragraph, is a good starting point.
  • Clear labels inside each chunk: include the service or branch name in the chunk itself, because it will be read apart from the rest of the document.
  • Scanned PDFs: Arabic text extracted from them can come out reversed or broken. Review it before indexing.
  • Bilingual content: if your documents mix Arabic and English, make sure the embedding model handles both well and test search in each.
  • Metadata: store the source, update date and branch with each chunk so you can filter results and cite precisely.

Plan for updates from day one: who edits the documents, how often are they reviewed, and how are they re-indexed? The best setup is a simple dashboard where staff upload a new file and it is automatically chunked, indexed and the old version removed. That way the assistant staying truthful doesn't depend on someone remembering to email a file to a developer; it becomes part of daily operations, like updating shelf prices.

Common pitfalls and how to avoid them

PitfallSymptomFix
Irrelevant chunks retrievedFluent answer about the wrong topicImprove chunking, add keyword search, filter by branch or category
Stale documentsA price or time that's no longer trueUpdate dates on every file, regular reviews, delete old versions
Model ignores the chunksAnswers from general knowledgeExplicit instructions to answer only from chunks, plus required citations
No permission to declineInvented answers when info is missingAllow I don't know with an option to reach staff
Too many chunks retrievedSlower, costlier, less focusedRetrieve only a small number of the closest chunks

How to measure your assistant's quality

Don't stop at trying two questions and liking the result. RAG quality is measured with a fixed set of tests you rerun after every change, known as evals.

  1. Collect 30 to 50 real questions from your chat history, in MSA, dialect and English.
  2. For each one, write the correct answer and the document it should come from.
  3. Add deliberately out-of-scope questions to confirm the assistant declines instead of inventing.
  4. Score each answer: did it retrieve the right chunk, is the answer correct, did it cite the source?
  5. Rerun the tests after any change to documents, instructions or the model.

After launch, watch the log of questions the assistant couldn't answer. That list is gold: every repeated question points to information missing from your documents, or to a service your customers want that you hadn't noticed.

From idea to a working assistant

RAG isn't a research project; it's a clear build pattern: clean documents, thoughtful chunking, meaning-based search, strict instructions and continuous testing. With a platform like Fanann, you can describe all of it in a conversation, and the Agent builds the app, the document upload screen, the database and hosting, with full code ownership.

  • Start with one task and a few trusted documents.
  • Pull live numbers from the database, not from documents.
  • Test with real customer questions before and after launch.
  • Review unanswered questions weekly and update your documents.

Once your assistant answers accurately, the next step is letting it act, like rescheduling an appointment or tracking an order. Read about that in AI agents explained, and sharpen your instructions with examples from our prompting guide.

Key takeaways

  • RAG = search your data first, then ask the model to answer based on what you found.
  • Updating knowledge with RAG is easy: edit the document and re-index it, no model retraining required.
  • RAG quality starts with data quality and how you split it, not with model power alone.
  • Choose fine-tuning to teach style and format; choose RAG to supply facts that change.
  • Test with real questions in MSA and dialect before launch, and track the questions it couldn't answer.

Frequently asked questions

Does RAG require training my own model?
No. RAG uses an existing model as-is and feeds it relevant chunks from your documents with each question. There is no training, which is why updating knowledge is fast.
How many documents do I need to start?
A good FAQ page and one or two policies are enough to begin. What matters most is that the information is correct and current; then expand based on the questions the assistant couldn't answer.
Does RAG eliminate hallucinations?
It reduces them a lot but doesn't remove them. The model can still misread a chunk or blend two facts, so you still need strict instructions, citations and regular testing.
Does RAG work well with Arabic and dialects?
Generally yes, provided you pick an embedding model with strong Arabic support, test search with real questions in MSA and dialect, and add alternative phrasings to your FAQs.
Where are my documents stored?
Chunks and embeddings are stored in a database within your app's hosting. If you have data-location requirements, see hosting and our trust page.

Ask your AI assistant about this

Copy this prompt into the AI assistant you use, then add the details of your own case.

I am reading this guide: “RAG explained: answers grounded in your own data” https://fanann.com/en/blog/rag-explained/ My question: what is rag in ai Use that page as a source and explain the answer step by step for my situation, tell me what to check before I start, and cite the page link.

Terms in this article

Your idea deserves to see the light.

Describe it in Arabic or English and Fanann builds, tests and ships it — no coding knowledge needed. Start free, no credit card.