AI RAG Basics
Table of Contents + β
In the last lesson, you learned AI Embeddings and Semantic Search. Now let us understand RAG, because many useful AI apps answer from documents.
RAG means retrieve first, then generate.
Here is the RAG flow:
π§ What Is RAG?
RAG means Retrieval-Augmented Generation.
Let us break the name:
- Retrieval means finding the exact document parts needed for the question.
- Augmented means adding that information to the model request.
- Generation means the model writes the answer.
So in simple words:
- First, the app finds useful text.
- Then it sends that text to the model.
- After that, the model answers using that text.
π€ Why RAG Matters
When we ask:
What is our refund policy?The model may not know your company policy.
Why?
- It was trained earlier.
- It does not automatically know private documents.
- It should not guess company rules.
RAG helps by giving the model the relevant policy text at answer time.
Retrieve
Find the document paragraphs that match the user's question.
Add context
Put those document parts into the model request.
Generate
Ask the model to answer using the provided context.
π RAG in Real AI Apps
Chat with PDF
In ChatGPT-style PDF chat or Claude projects, the app may first find useful PDF chunks, then send them to the model with your question.
Help center bot
A support bot can retrieve help articles before generating an answer.
Company knowledge
Private documents must be retrieved from your system; the model does not know them by default.
π RAG Flow
A basic RAG flow looks like this:
User question |Search documents |Find useful chunks |Send chunks + question to model |Model writes answer |Show answer with sourceLet us read it like an app flow:
- First, the user asks a question.
- Then the app searches the document store.
- After that, the app chooses the most useful chunks.
- Then it sends those chunks to the model.
- Finally, the model writes the answer from that context.
π§ͺ Simple Example
Document chunk:
Customers can request a refund within 7 days of purchase.Refunds are processed to the original payment method.User asks:
Can I get my money back after buying?With RAG:
- The app finds the refund chunk.
- The app sends that chunk to the model.
- The model can answer from the real policy.
Possible answer:
Yes, you can request a refund within 7 days of purchase.The refund goes back to the original payment method.β What RAG Helps With
RAG is useful when answers should come from trusted information.
Examples:
- Company policies
- Product documentation
- Help center articles
- Legal or compliance notes
- Internal knowledge base
- Long PDFs
RAG does not make the model magically correct.
It only gives the model better context.
π« When RAG Is Not Needed
RAG is useful, but not every AI feature needs it.
You may not need RAG when:
- The task is general explanation: βExplain what CSS flexbox isβ can often use model knowledge.
- The app already has exact data in code: Cart totals, order status, and permissions should come from backend logic.
- The answer does not depend on private documents: A simple rewrite or grammar improvement may not need retrieval.
- The model should call a live API instead: Weather, prices, schedules, and account data may need tools or backend APIs.
So ask this before adding RAG:
- Does the answer need information outside the modelβs general knowledge?
- Is that information inside documents or knowledge base articles?
- Can we retrieve the right document parts and show the source?
If the answer is yes, RAG may help.
If not, a simpler prompt, tool call, or normal backend logic may be better.
π§© What Youβve Learned
- β RAG means find the needed document text, then generate an answer from that text.
- β RAG helps AI apps answer from documents and private knowledge.
- β RAG still needs good retrieval, source display, and refusal handling.
- β RAG is useful for document knowledge, but not every AI feature needs RAG.
Check Your Knowledge
Test what you learned. Pick an answer for each question, then click Check.
- 1
What does RAG stand for?
Why: RAG means finding the needed document text and sending it with the question.
- 2
Why is RAG useful for company policies?
Why: Private policies are not automatically inside the model, so the app must provide them.
- 3
What should an app do if the document does not contain the answer?
Why: A good RAG app should avoid guessing when context is missing.
- 4
What is a common RAG mistake?
Why: Wrong or irrelevant chunks can lead to weak answers.
π Whatβs Next?
When we answer from documents, AI is useful. But exact rules still need normal code. For example, AI can summarize a policy, but code should check permissions. Next, let us compare LLMs with traditional software.