What is RAG and how can an AI respond using your documents?
Published on 2026-10-20 by frfrand
RAG explained with examples: how an AI searches for information in documents, what embeddings are, why it cites sources, and where it can go wrong.

Short answer: RAG is a technique that combines information retrieval with response generation using artificial intelligence. Its acronym stands for Retrieval-Augmented Generation: generation augmented through retrieval. Instead of asking a model to respond solely based on what it learned during training, relevant information is first searched for and provided as context.
Imagine you have one hundred internal company manuals. A person asks "how can I request vacation?". A general model might invent a policy or answer with rules from another company. A RAG system attempts to find the correct section of your manuals and respond based on it.
The librarian example
Think of a library. The librarian does not need to memorize all the books. It is enough to know how to locate the indicated chapter, read it, and explain the answer.
With RAG something similar happens, although automated: first document fragments are retrieved and then a model builds the response. It is not the same as training the model from scratch with all the files.
What steps does a RAG system follow?
A typical flow has several stages:
- Preparation: documents are loaded, their content is extracted, and they are divided into manageable fragments.
- Indexing: those fragments are stored with useful information, sometimes converting them into vectors called embeddings.
- Question: a person asks something in natural language.
- Retrieval: the system identifies the most related fragments.
- Generation: the model receives the question and the retrieved fragments to draft a response.
Not all systems use exactly the same search. Some combine keyword search with semantic search and then reorder the results.
What are embeddings?
They are numerical representations of information used to compare similarities. Two sentences can express the same idea with different words: "how do I request days off?" and "procedure to request vacation".
A literal search may not easily detect the relationship. A semantic representation can help find related fragments by meaning.
But an embedding is not perfect knowledge. It can find a similar paragraph even if it is old, irrelevant, or contradictory. That is why it is important to combine it with filters, dates, permissions, and evaluation of results.
Does RAG eliminate hallucinations?
No. It can reduce invented responses when it retrieves appropriate sources, but the model can still misinterpret a fragment, omit a condition, or respond with excessive confidence.
If internal policy states that "only requests approved ten days in advance," the system should not respond "yes, you can request them tomorrow" without checking that condition.
Good design allows showing the sources consulted and supports responding "I did not find sufficient information" when appropriate.
The permissions problem
Imagine that the same system contains public documents, client contracts, and employee salaries. It is not enough for the search to find something relevant: it must verify whether that person is authorized to view it.
Control should not depend on politely asking the model to ignore private documents. Permissions must be applied during data retrieval and access.
There may also be documents with malicious instructions intended to deceive the model. Those fragments should be treated as untrusted information, not as authoritative orders.
When does it make sense to use it?
A support assistant based on updated manuals, conversational search in technical documentation, or an internal FAQ system are good candidates. RAG is less useful if the problem only requires querying an exact number from a database through a conventional API.
Sometimes the most reliable solution is a SQL query or a defined function, not a semantic search.
What maintenance does it need?
If documents change, it is advisable to update the index. If a policy expires, it must be removed or its date indicated. Tests with real questions and an error log are also needed to improve retrieval.
Measure whether the retrieved fragments are relevant before blaming the model for an incorrect answer.
Where does ArduMaker fit in?
A RAG architecture can run with components hosted on VPS, databases, and AI services. In ArduMaker you can install pieces like PostgreSQL or Redis on your VPS, deploy your application from GitHub, and, with the AI Router, create API keys with spending limits to call models through OpenRouter. Retrieval, permission control, and source quality, on the other hand, are designed in your project: none of those pieces solves them alone.
In summary: RAG allows an AI to consult external information before answering. Its usefulness depends as much on the search engine and the data as on the model itself.
Frequently asked questions
What is the difference between RAG and fine-tuning?
RAG passes updated information to the model with each question, without modifying it: if a document changes, it is enough to reindex it. Fine-tuning adjusts the model itself with examples and is more useful for teaching it a style or format than for keeping it up to date with changing data.
Do I need a vector database?
Not always. For a few documents, a well-implemented keyword search may suffice. If you need semantic search, there are dedicated vector databases and also extensions like pgvector for PostgreSQL; check that your installation has it before designing around it.
Sources: Security of RAG systems according to OWASP · Introduction to OpenAI embeddings.
