Skip to content
AI2 min read

What is RAG (retrieval-augmented generation)?

Short answer

RAG (retrieval-augmented generation) first searches your documents for passages related to the user's question, then sends them with the question to a language model so it answers from them. The model can then answer from your current company data, invents less and can cite its source.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. The steps of RAG
  2. Example
  3. Common problems
  4. On ArabyHost

A language model doesn’t know your store’s return policy, your clinic’s opening hours or your staff handbook. RAG solves that without training a new model: you hand it the right information at the right moment.

The steps of RAG

First: preparation, once and again whenever documents change

  1. Chunking: split documents into small passages, such as one or a few paragraphs.
  2. Embedding: turn each passage into a vector of numbers that represents its meaning.
  3. Storage: save the vectors with the passage text in a vector database or index.

Then: on every question

  1. Turn the question into a vector and find the closest passages.
  2. Add those passages to the prompt with an instruction like “Answer only from the text below; if the answer isn’t there, say you don’t know.”
  3. The model generates the answer, and the source can be shown next to it.

Example

A customer asks: “Can I return a product after two weeks?” The search finds a passage in the returns policy saying returns are accepted within 14 days of delivery, and the model replies: “Yes, as long as no more than 14 days have passed since delivery,” with a link to the policy page. Asked about something that isn’t in the documents, the instruction makes it admit it doesn’t know instead of inventing an answer.

Common problems

  • Chunks too big or too small: big ones dilute focus; tiny ones lose context.
  • Stale index: if documents change and aren’t re-indexed, answers go out of date.
  • Poor retrieval: combining meaning-based and keyword search (hybrid search) helps.
  • Prompt injection: a document containing malicious instructions can steer the model, so don’t index untrusted content without checking it.

If you want the system to decide for itself when and where to search, you’re moving towards an AI agent that uses search as a tool.

On ArabyHost

Build a RAG app in Python (3.9 to 3.12) or Node.js on AI/Developer plans, run it through Phusion Passenger, and refresh the index regularly with a cron job. There are no GPUs, so use embedding and model services through an API and keep your API keys in environment variables. Store passages in a MySQL/MariaDB database, in an index inside your account, or in an external vector database. See AI app hosting and the AI app deployment guide.

FAQ

How is RAG different from fine-tuning?

RAG adds information to the prompt at request time, so answers update as soon as the documents do. Fine-tuning changes the model itself through training and suits teaching a fixed style or format, not storing facts that change.

Do I need a vector database?

Not always. For a small set of documents, plain text search or a simple file-based index is enough. A vector database pays off when the data grows and you need search by meaning, not just keywords.

Does RAG work with Arabic documents?

Yes, as long as the embedding model handles Arabic well. Normalizing text before indexing also helps, such as unifying hamza forms and taa marbuta and stripping diacritics, so questions match the text.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.