Table of contents
The short answer
RAG (retrieval-augmented generation) is a pattern with two steps. First, the agent searches a set knowledge source for information related to a question. Then it uses that information to write its answer. It doesn't rely only on what the model learned in training.
RAG gives the agent knowledge you can update and a source you can trace. It is the usual foundation for an agent that needs precise knowledge about a specific company or product. To see how RAG fits into the wider agent design, read the AI agents guide. RAG is especially common in customer service agents and sales agents, where grounded answers are critical.
RAG explained plainly
A language model on its own answers from the general "memory" it gained in training. That memory is general and may be out of date. It knows nothing about your company's policies or your product. This is distinct from AI agent memory, which stores session and user-specific context rather than static knowledge.
RAG adds a step before the model writes. It searches a set knowledge source (documents, FAQs, policies) for the passages that best match the question. Then it passes those passages to the model, so the model builds its answer on them.
The practical difference: a generic answer that sounds right, versus one based on real text you can check.
The retrieval loop
- The user's question comes in. The agent works out what actually needs looking up.
- It searches the knowledge base for the passages closest in meaning.
- It passes the best passages to the model as extra context, not as absolute fact.
- It builds the reply on those passages and can point back to their source.
- If no passage is a close enough match, the agent should say so instead of making up an answer.
Chunking and sources
Before search can work, documents are split into chunks of the right size. Each chunk should be small enough to be precise, but large enough to make sense on its own.
Poor chunking is one of the most common reasons search goes wrong. Examples are passages cut off mid-idea, or chunks so long they mix several topics. The agent can't find what was never split in a way that keeps its meaning.
Choosing sources matters just as much. One current, trusted source beats dozens of old documents that contradict each other.
Arabic and bilingual sources
Many GCC knowledge bases mix Arabic and English, and customers often ask in dialect while the policy is written in formal Arabic. A few practical checks:
- Make sure scanned Arabic PDFs contain real text, not just images; a page the system cannot read cannot be retrieved.
- Keep one language version as the reference for each policy, and tag documents by language so retrieval can be filtered (Wkil knowledge bases support tags and filtering, for example by language or department).
- Split at headings and paragraphs, not mid-sentence, with a small overlap between chunks.
- Before launch, collect 20 to 30 real customer questions, including dialect phrasing such as "كم رسوم التوصيل للرياض؟", and check which passages come back. Wkil's retrieval debugging shows the retrieved passages with their similarity scores and ranking, so you can fix the document or the chunk size instead of guessing.
When to retrieve vs the alternatives
- Search the knowledge base when the agent needs fairly stable information: a policy, a procedure or product details.
- Call a tool when it needs to act or get live data that keeps changing: an account balance, an order status or sending an email.
- Use both when the answer needs both: "Can I still return this order?" needs the return policy (retrieval) and the order's delivery date (a tool call).
- Ask a human when neither knowledge nor tools can answer the question, or when the risk is high. See human-in-the-loop design for how to build that escalation path.
- A simple rule: knowledge is for reading, tools are for acting, and a human decides when things are unclear or risky.
Table: RAG vs the alternatives
| Approach | When to use | How it updates | Main constraint |
|---|---|---|---|
| RAG | Text knowledge that changes over time | Update the source only | Quality depends on chunking and sources |
| Fine-tuning | Changing the model's fixed style or behaviour | Requires retraining | Costly, unsuited to fast-changing facts |
| Tools | Taking an action or fetching live data | Instant, via the connected system | Not suited to general text knowledge |
| Memory | Information specific to a user or session | Written and updated deliberately | Not a general, trustworthy knowledge source |
Citations and traceability
One of RAG's biggest strengths is that you can link an answer back to its source — the document or passage it was built on. That makes it possible to review and check the answer. You can't do that when a model answers only from general memory.
Any serious agent system should let you trace an answer to its source. It shouldn't present the answer as bare fact. This traceability is a key part of AI agent security and governance — especially for regulated industries like banking and finance.
Common failure modes
- Searching an old source that's never refreshed.
- Poor chunking that strips passages of context and makes search less accurate.
- Writing an answer even when no passage is a close match, instead of admitting the information is missing.
- Using RAG to take actions. It's built to find text knowledge, not to carry out tasks.
Related reading from Wkil
FAQ
Ready to build your first digital employee?
Start building an agent on the platform, or browse the ready-made Agent Marketplace.