Bỏ qua đến nội dung

[NÂNG CAO] RAG: Kết Nối AI Với Knowledge Base Riêng

Kỹ thuật nâng cao - Cho phép AI 'đọc' docs/PDFs của bạn trước khi trả lời

[NÂNG CAO] RAG: AI Đọc Docs Của Bạn

⚠️ CẢNH BÁO: BÀI NÂNG CAO

Ai nên đọc:

  • Dùng ChatGPT Enterprise/Team
  • Dùng Notion AI / Perplexity Pro
  • Company có knowledge base lớn (docs, reports, policies…)

Ai có thể SKIP:

  • Chỉ dùng ChatGPT free/Plus cơ bản
  • Không có docs nội bộ để AI đọc
  • Chỉ cần viết content general

Nếu bạn KHÔNG có knowledge base nội bộ → SKIP bài này!


📌 TLDR

RAG (Retrieval-Augmented Generation) = AI tìm thông tin từ docs/PDFs/database CỦA BẠN trước khi trả lời. Khác normal AI (chỉ dựa vào training data), RAG cho phép AI “đọc” company docs, reports, policies… rồi mới answer.


Vấn Đề: AI Không Biết Data Riêng Của Bạn

Scenario:

Bạn hỏi ChatGPT:

"Summarize Q3 marketing performance của công ty"

ChatGPT trả lời:

“Tôi không có access vào data nội bộ công ty bạn…”

Tại sao? → ChatGPT chỉ biết public internet data! → Không biết reports/docs/emails riêng của bạn!


Solution: RAG

Với RAG:

  1. Upload Q3 report.pdf vào system
  2. Hỏi: “Summarize Q3 performance”
  3. AI TÌM info trong PDF → Trả lời based on YOUR data!

RAG Là Gì? (Simple Explanation)

2 Steps:

Step 1: RETRIEVAL (Tìm)

  • AI search trong knowledge base của bạn
  • Tìm fragments liên quan đến câu hỏi

Step 2: GENERATION (Tạo)

  • Dùng fragments đó để viết answer
  • Cite sources (nếu có)

Ví Dụ Đơn Giản:

Knowledge Base:

  • Company policies.pdf
  • Employee handbook.pdf
  • Benefits guide.pdf

Question: “Chính sách nghỉ phép là gì?”

RAG Process:

1. RETRIEVAL:
   AI tìm trong 3 PDFs
   → Tìm thấy section "Leave Policy" trong handbook.pdf
   
2. GENERATION:
   "According to employee handbook page 15:
   - Annual leave: 12 days/year
   - Sick leave: 10 days/year
   - After 2 years: +2 days annual leave"

Accurate (based on real docs)
Cited (page 15 handbook)
Grounded (không hallucinate!)


Khi Nào CẦN RAG?

✅ Cần RAG Khi:

1. Company Knowledge Base:

- Policies, guidelines, SOPs
- Product docs, specifications
- Meeting notes, reports
- Customer data, tickets

2. Research/Legal/Finance:

- Cite nguồn bắt buộc
- Accuracy critical
- Compliance requirements

3. Customer Support:

- FAQs, support docs
- Product manuals
- Troubleshooting guides

❌ KHÔNG Cần RAG Khi:

1. General Content:

"Viết blog về trends" → Normal AI đủ
"Brainstorm ideas" → Zero-shot đủ

2. No Internal Docs:

Startup mới, chưa có docs
→ RAG = overkill!

3. Public Information:

AI already knows public info
→ Không cần RAG

Tools Có RAG (No-Code)

1. ChatGPT (Paid Plans)

ChatGPT Plus ($20/mo):

  • Upload files per conversation
  • Max 10 files

ChatGPT Team/Enterprise:

  • Upload company docs
  • Search across all conversations
  • Better security

How to use:

1. Click 📎 (attach)
2. Upload PDF/docx
3. Ask questions

2. Notion AI

Built-in RAG:

  • Searches your Notion workspace
  • Pages, databases, notes

Example:

@NotionAI "Summarize all meeting notes from Q4"

→ AI searches workspace
→ Finds all meeting notes
→ Summarizes

3. Perplexity Pro

Web + Your Files:

  • Upload PDFs
  • AI searches web + your docs
  • Cites sources

Use case:

Research combining:
- Your company data +
- Public market data

4. Claude (Anthropic)

Projects Feature:

  • Upload docs to project
  • AI remembers context
  • 200K+ token context window

Best for: Long documents (100+ pages)


RAG Workflow Example

Case: Customer Support Bot

Setup:

Knowledge Base:
├── product_manual.pdf (150 pages)
├── faq.pdf (20 pages)
├── troubleshooting.pdf(50 pages)
└── warranty_policy.pdf (10 pages)

Customer asks:

“Máy không bật được, làm sao?”

RAG Process:

1. RETRIEVAL:
   Search 4 PDFs for "không bật"
   
   Found in troubleshooting.pdf page 12:
   "Vấn đề: Máy không bật
    Giải pháp:
    1. Check nguồn điện
    2. Giữ nút nguồn 10s
    3. Nếu vẫn không được → Contact support"

2. GENERATION:
   AI: "Dựa vào troubleshooting guide:
   
   Bước 1: Kiểm tra nguồn điện đã cắm chưa
   Bước 2: Giữ nút nguồn 10 giây
   Bước 3: Nếu vẫn không được, liên hệ: 
           hotline 1900-xxxx
   
   (Source: Troubleshooting guide p.12)"

✅ Accurate (from real docs)
✅ Step-by-step (clear)
✅ Cited source (trustworthy)


Prompting với RAG

Template 1: Simple Query

[Upload docs first]

"Based on [specific doc/section],
answer: [question]"

Example:
"Based on Q3 report,
what was our top-performing channel?"

Template 2: Multi-Doc Analysis

"Search across all uploaded documents for:
[topic/keyword]

Summarize findings and cite sources."

Example:
"Search all meeting notes for decisions about
pricing strategy. Summarize and cite which meeting."

Template 3: Comparison

"Compare information between:
- [Doc A]
- [Doc B]

Focus on [aspect]"

Example:
"Compare Q2 vs Q3 revenue metrics.
What changed and why?"

Best Practices

✅ DO:

1. Organize Docs Well:

Clear naming:
✅ Q3_Marketing_Report_2025.pdf
❌ report_final_final_v2.pdf

2. Ask Specific Questions:

✅ "What was organic traffic growth in Q3 per marketing report?"
❌ "Cho tui biết về marketing"

3. Request Citations:

"Answer based on docs and CITE which document + page"

❌ DON’T:

1. Upload Irrelevant Docs:

❌ Upload 50 PDFs về mọi thứ
✅ Upload only relevant docs

2. Vague Questions:

❌ "Nói về công ty"
✅ "Summarize company mission from handbook p.3"

3. Expect Perfect Retrieval:

RAG không phải magic!
Nếu info không có trong docs → AI không biết

RAG Advanced: For Developers

Tech Stack (If Building Custom):

1. Vector Database:

  • Pinecone
  • Weaviate
  • ChromaDB
  • Qdrant

2. Frameworks:

  • LangChain
  • LlamaIndex
  • Haystack

3. Embeddings:

  • OpenAI text-embedding-3-large
  • Sentence Transformers

Process:

1. Chunk documents (500-1000 tokens)
2. Create embeddings (vectors)
3. Store in vector DB
4. Query → Similarity search
5. Retrieve top-K chunks
6. Feed to LLM for generation

⚠️ Warning: Technical setup - Need developer!


Limitations of RAG

❌ Challenges:

1. Quality Depends on Docs:

Bad docs → Bad answers
Outdated docs → Outdated answers

2. Retrieval Not Perfect:

Sometimes AI tìm wrong chunks
→ Irrelevant answers

3. Cost:

RAG = More processing
→ Slower + More expensive than normal AI

4. Security:

Upload sensitive docs → Need secure system
Free tools → Risk!

Real Case Study: Law Firm

Problem:

  • 10,000+ legal documents
  • Lawyers spend 3h/day searching precedents

Solution: RAG System

Setup:

Knowledge Base:
- All case files (10k docs)
- Legal precedents
- Contract templates
- Research notes

Workflow:

Lawyer asks:
"Find precedents for trademark dispute in e-commerce"

RAG:
1. Search 10k docs
2. Find 15 relevant cases
3. Summarize key points
4. Cite case numbers

Time: 2 minutes (vs 3 hours!)

Results:

  • ⏱️ 90% time saved (3h → 20min)
  • ✅ Better coverage (AI checks ALL docs)
  • 📚 Cited sources (trust!)

ROI: $50K/year saved per lawyer


Combo Techniques

RAG + Chain of Thought:

"Search docs for [topic].
Then think step by step to answer [question]."

RAG + Self-Consistency:

"Find info from docs.
Verify answer using 2 different doc sections.
If conflict, explain difference."

Action Plan (If You Need RAG)

Tuần 1: Setup

  • Choose tool (ChatGPT Team / Notion AI / etc)
  • Organize 10-20 key docs
  • Upload and test

Tuần 2: Test

  • Ask 10 questions you know answers
  • Verify accuracy
  • Note what works/doesn’t

Tuần 3: Scale

  • Add more docs
  • Train team to use
  • Create FAQ templates

Tháng 2+: Optimize

  • Clean up docs (remove outdated)
  • Refine prompt templates
  • Measure time saved

Kết Luận

🎯 RAG Summary

What: AI searches YOUR docs before answering

When to use:

  • Company knowledge base
  • Need accurate + cited answers
  • Customer support

When NOT to use:

  • No internal docs
  • General content creation
  • Budget constrained

⚠️ Final Warning

Bạn có THỰC SỰ cần RAG?

CẦN nếu:

  • ✅ Có 100+ docs nội bộ
  • ✅ Cần cite sources
  • ✅ Accuracy critical

KHÔNG CẦN nếu:

  • ❌ Startup nhỏ, ít docs
  • ❌ Chỉ viết content
  • ❌ Chỉ dùng ChatGPT free

90% người KHÔNG CẦN RAG!

Quay lại practice 6 techniques cơ bản! 💪


Resources:

  • ChatGPT Enterprise: openai.com/enterprise
  • LangChain docs: langchain.com
  • RAG Paper: “Retrieval-Augmented Generation” (Lewis et al., 2020)

Next: If you need self-improving AI → Read about Reflexion
Otherwise: Back to mastering core techniques! ✅

Câu hỏi ôn tập

Trả lời xong, bấm “Kiểm tra đáp án” để mở ChatGPT chấm tự động.

1

Mục tiêu chính của bài học "[NÂNG CAO] RAG: Kết Nối AI Với Knowledge Base Riêng" là gì?

2

Tóm tắt 3 ý chính của bài học bằng lời của bạn (ngắn gọn, rõ ràng).

3

Nêu 1 tình huống thực tế bạn có thể áp dụng kiến thức từ bài học này.