@xdev-asia/xdev-knowledge-mcp 1.0.40 → 1.0.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/content/series/luyen-thi/luyen-thi-aws-ai-practitioner/chapters/01-domain-1-fundamentals-ai-ml/lessons/01-bai-1-ai-ml-deep-learning-concepts.md +287 -0
- package/content/series/luyen-thi/luyen-thi-aws-ai-practitioner/chapters/01-domain-1-fundamentals-ai-ml/lessons/02-bai-2-ml-lifecycle-aws-services.md +258 -0
- package/content/series/luyen-thi/luyen-thi-aws-ai-practitioner/chapters/02-domain-2-fundamentals-generative-ai/lessons/03-bai-3-generative-ai-foundation-models.md +218 -0
- package/content/series/luyen-thi/luyen-thi-aws-ai-practitioner/chapters/02-domain-2-fundamentals-generative-ai/lessons/04-bai-4-llm-transformers-multimodal.md +232 -0
- package/content/series/luyen-thi/luyen-thi-aws-ai-practitioner/chapters/03-domain-3-applications-foundation-models/lessons/05-bai-5-prompt-engineering-techniques.md +254 -0
- package/content/series/luyen-thi/luyen-thi-aws-ai-practitioner/chapters/03-domain-3-applications-foundation-models/lessons/06-bai-6-rag-vector-databases-knowledge-bases.md +244 -0
- package/content/series/luyen-thi/luyen-thi-aws-ai-practitioner/chapters/03-domain-3-applications-foundation-models/lessons/07-bai-7-fine-tuning-model-customization.md +247 -0
- package/content/series/luyen-thi/luyen-thi-aws-ai-practitioner/chapters/03-domain-3-applications-foundation-models/lessons/08-bai-8-amazon-bedrock-deep-dive.md +276 -0
- package/content/series/luyen-thi/luyen-thi-aws-ai-practitioner/chapters/04-domain-4-responsible-ai/lessons/09-bai-9-responsible-ai-fairness-bias-transparency.md +224 -0
- package/content/series/luyen-thi/luyen-thi-aws-ai-practitioner/chapters/04-domain-4-responsible-ai/lessons/10-bai-10-aws-responsible-ai-tools.md +252 -0
- package/content/series/luyen-thi/luyen-thi-aws-ai-practitioner/chapters/05-domain-5-security-compliance/lessons/11-bai-11-ai-security-data-privacy-compliance.md +279 -0
- package/content/series/luyen-thi/luyen-thi-aws-ai-practitioner/chapters/05-domain-5-security-compliance/lessons/12-bai-12-exam-strategy-cheat-sheet.md +229 -0
- package/content/series/luyen-thi/luyen-thi-aws-ai-practitioner/index.md +257 -0
- package/content/series/luyen-thi/luyen-thi-aws-ml-specialty/index.md +240 -0
- package/content/series/luyen-thi/luyen-thi-gcp-ml-engineer/index.md +225 -0
- package/data/categories.json +16 -4
- package/data/quizzes.json +764 -0
- package/data/settings.json +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: 019c9619-lt01-d3-l05
|
|
3
|
+
title: 'Bài 5: Prompt Engineering Techniques'
|
|
4
|
+
slug: bai-5-prompt-engineering-techniques
|
|
5
|
+
description: >-
|
|
6
|
+
Zero-shot, few-shot, Chain-of-Thought prompting.
|
|
7
|
+
System prompts, prompt templates, negative prompting.
|
|
8
|
+
Prompt engineering best practices cho AWS AI Practitioner exam.
|
|
9
|
+
duration_minutes: 55
|
|
10
|
+
is_free: true
|
|
11
|
+
video_url: null
|
|
12
|
+
sort_order: 1
|
|
13
|
+
section_title: "Domain 3: Applications of Foundation Models (28%)"
|
|
14
|
+
course:
|
|
15
|
+
id: 019c9619-lt01-7001-c001-lt0100000001
|
|
16
|
+
title: 'Luyện thi AWS Certified AI Practitioner (AIF-C01)'
|
|
17
|
+
slug: luyen-thi-aws-ai-practitioner
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
<div style="text-align: center; margin: 2rem 0;">
|
|
21
|
+
<img src="/storage/uploads/2026/04/aws-aif-bai5-prompt-engineering.png" alt="Prompt Engineering Techniques" style="max-width: 800px; width: 100%; border-radius: 12px;" />
|
|
22
|
+
<p><em>Prompt Engineering Techniques: Zero-shot, Few-shot và Chain-of-Thought</em></p>
|
|
23
|
+
</div>
|
|
24
|
+
|
|
25
|
+
<h2 id="prompt-engineering"><strong>1. What is Prompt Engineering?</strong></h2>
|
|
26
|
+
|
|
27
|
+
<p><strong>Prompt Engineering</strong> là nghệ thuật thiết kế input (prompt) để nhận được output mong muốn từ Foundation Models. Đây là cách <strong>rẻ nhất và nhanh nhất</strong> để customize FM behavior — không cần training hay fine-tuning.</p>
|
|
28
|
+
|
|
29
|
+
<h3 id="prompt-components"><strong>1.1. Components of a Prompt</strong></h3>
|
|
30
|
+
|
|
31
|
+
<pre><code class="language-text">┌────────────────────────────────────────────┐
|
|
32
|
+
│ SYSTEM PROMPT (optional) │
|
|
33
|
+
│ "You are a helpful AWS solutions │
|
|
34
|
+
│ architect. Answer concisely." │
|
|
35
|
+
├────────────────────────────────────────────┤
|
|
36
|
+
│ CONTEXT (optional) │
|
|
37
|
+
│ Background info, documents, data │
|
|
38
|
+
├────────────────────────────────────────────┤
|
|
39
|
+
│ USER PROMPT (required) │
|
|
40
|
+
│ The actual question or instruction │
|
|
41
|
+
├────────────────────────────────────────────┤
|
|
42
|
+
│ EXAMPLES (optional, for few-shot) │
|
|
43
|
+
│ Input → Output pairs │
|
|
44
|
+
├────────────────────────────────────────────┤
|
|
45
|
+
│ OUTPUT FORMAT (optional) │
|
|
46
|
+
│ "Respond in JSON", "Use bullet points" │
|
|
47
|
+
└────────────────────────────────────────────┘
|
|
48
|
+
</code></pre>
|
|
49
|
+
|
|
50
|
+
<h2 id="prompting-techniques"><strong>2. Prompting Techniques</strong></h2>
|
|
51
|
+
|
|
52
|
+
<h3 id="zero-shot"><strong>2.1. Zero-shot Prompting</strong></h3>
|
|
53
|
+
|
|
54
|
+
<p>Gửi prompt <strong>không có ví dụ</strong>. Model dựa hoàn toàn vào knowledge đã học.</p>
|
|
55
|
+
|
|
56
|
+
<pre><code class="language-text">Prompt: "Classify the sentiment of this review:
|
|
57
|
+
'The product arrived damaged and customer service was unhelpful.'
|
|
58
|
+
|
|
59
|
+
Sentiment:"
|
|
60
|
+
|
|
61
|
+
Output: "Negative"
|
|
62
|
+
</code></pre>
|
|
63
|
+
|
|
64
|
+
<p><strong>When to use:</strong> Simple, well-defined tasks mà model đã hiểu rõ.</p>
|
|
65
|
+
|
|
66
|
+
<h3 id="few-shot"><strong>2.2. Few-shot Prompting</strong></h3>
|
|
67
|
+
|
|
68
|
+
<p>Cung cấp <strong>một vài examples</strong> trước khi đưa ra task thực tế. Giúp model hiểu expected format và logic.</p>
|
|
69
|
+
|
|
70
|
+
<pre><code class="language-text">Prompt: "Classify these reviews:
|
|
71
|
+
|
|
72
|
+
Review: 'Amazing quality, fast shipping!' → Positive
|
|
73
|
+
Review: 'Terrible experience, never again.' → Negative
|
|
74
|
+
Review: 'It's okay, nothing special.' → Neutral
|
|
75
|
+
|
|
76
|
+
Review: 'The product exceeded my expectations!' →"
|
|
77
|
+
|
|
78
|
+
Output: "Positive"
|
|
79
|
+
</code></pre>
|
|
80
|
+
|
|
81
|
+
<p><strong>When to use:</strong> Khi cần model tuân theo specific format hoặc logic pattern mà zero-shot không đạt đủ chất lượng.</p>
|
|
82
|
+
|
|
83
|
+
<h3 id="one-shot"><strong>2.3. One-shot Prompting</strong></h3>
|
|
84
|
+
|
|
85
|
+
<p>Variation của few-shot nhưng chỉ cung cấp <strong>1 example</strong>. Dùng khi bạn muốn set pattern nhưng context window bị hạn chế.</p>
|
|
86
|
+
|
|
87
|
+
<h3 id="cot"><strong>2.4. Chain-of-Thought (CoT) Prompting</strong></h3>
|
|
88
|
+
|
|
89
|
+
<p>Yêu cầu model <strong>suy nghĩ step-by-step</strong> trước khi trả lời. Đặc biệt hiệu quả cho math, logic, và reasoning tasks.</p>
|
|
90
|
+
|
|
91
|
+
<pre><code class="language-text">WITHOUT CoT:
|
|
92
|
+
Q: "If a store has 3 boxes with 12 apples each, and gives
|
|
93
|
+
away 15 apples, how many are left?"
|
|
94
|
+
A: "21" (might be wrong without reasoning)
|
|
95
|
+
|
|
96
|
+
WITH CoT:
|
|
97
|
+
Q: "Think step by step: If a store has 3 boxes with 12
|
|
98
|
+
apples each, and gives away 15 apples, how many are left?"
|
|
99
|
+
A: "Step 1: Total apples = 3 × 12 = 36
|
|
100
|
+
Step 2: After giving away = 36 - 15 = 21
|
|
101
|
+
Answer: 21 apples"
|
|
102
|
+
</code></pre>
|
|
103
|
+
|
|
104
|
+
<blockquote>
|
|
105
|
+
<p><strong>Exam tip:</strong> "Which prompting technique improves reasoning accuracy?" → <strong>Chain-of-Thought</strong>. Key phrase: "think step by step" hoặc "explain your reasoning".</p>
|
|
106
|
+
</blockquote>
|
|
107
|
+
|
|
108
|
+
<h2 id="system-prompts"><strong>3. System Prompts & Personas</strong></h2>
|
|
109
|
+
|
|
110
|
+
<p><strong>System prompt</strong> defines the model's role, behavior, constraints, and output format. Nó "sets the stage" trước khi user interaction.</p>
|
|
111
|
+
|
|
112
|
+
<pre><code class="language-text">System Prompt:
|
|
113
|
+
"You are a financial advisor AI for XYZ Bank.
|
|
114
|
+
Rules:
|
|
115
|
+
- Only answer questions about banking and investments
|
|
116
|
+
- Never provide specific stock recommendations
|
|
117
|
+
- Always include a disclaimer
|
|
118
|
+
- Respond in a professional tone
|
|
119
|
+
- If asked about non-financial topics, politely redirect"
|
|
120
|
+
</code></pre>
|
|
121
|
+
|
|
122
|
+
<h3 id="system-prompt-use"><strong>System Prompt Best Practices:</strong></h3>
|
|
123
|
+
|
|
124
|
+
<table>
|
|
125
|
+
<thead><tr><th>Practice</th><th>Why</th></tr></thead>
|
|
126
|
+
<tbody>
|
|
127
|
+
<tr><td>Define a <strong>clear role</strong></td><td>Constrains model behavior to a domain</td></tr>
|
|
128
|
+
<tr><td>Set <strong>boundaries</strong></td><td>Prevents off-topic or harmful responses</td></tr>
|
|
129
|
+
<tr><td>Specify <strong>output format</strong></td><td>Ensures consistent, parseable outputs</td></tr>
|
|
130
|
+
<tr><td>Include <strong>examples</strong></td><td>Clarifies expected behavior</td></tr>
|
|
131
|
+
<tr><td>Add <strong>guardrails</strong></td><td>Prevents misuse (PII, harmful content)</td></tr>
|
|
132
|
+
</tbody>
|
|
133
|
+
</table>
|
|
134
|
+
|
|
135
|
+
<h2 id="advanced-techniques"><strong>4. Advanced Prompting Techniques</strong></h2>
|
|
136
|
+
|
|
137
|
+
<h3 id="negative-prompting"><strong>4.1. Negative Prompting</strong></h3>
|
|
138
|
+
|
|
139
|
+
<p>Chỉ rõ những gì model <strong>KHÔNG nên làm</strong>. Đặc biệt useful trong image generation.</p>
|
|
140
|
+
|
|
141
|
+
<pre><code class="language-text">Text generation:
|
|
142
|
+
"Summarize this article. Do NOT include opinions
|
|
143
|
+
or personal commentary. Do NOT exceed 100 words."
|
|
144
|
+
|
|
145
|
+
Image generation (Stable Diffusion):
|
|
146
|
+
Prompt: "Professional headshot, studio lighting"
|
|
147
|
+
Negative prompt: "blurry, cartoon, distorted, low quality"
|
|
148
|
+
</code></pre>
|
|
149
|
+
|
|
150
|
+
<h3 id="prompt-templates"><strong>4.2. Prompt Templates</strong></h3>
|
|
151
|
+
|
|
152
|
+
<p>Reusable prompt structures với <strong>placeholders</strong> cho dynamic content:</p>
|
|
153
|
+
|
|
154
|
+
<pre><code class="language-text">Template:
|
|
155
|
+
"Given the following {document_type}:
|
|
156
|
+
---
|
|
157
|
+
{content}
|
|
158
|
+
---
|
|
159
|
+
Extract the following information:
|
|
160
|
+
- {field_1}
|
|
161
|
+
- {field_2}
|
|
162
|
+
- {field_3}
|
|
163
|
+
Respond in JSON format."
|
|
164
|
+
</code></pre>
|
|
165
|
+
|
|
166
|
+
<h3 id="prompt-chaining"><strong>4.3. Prompt Chaining</strong></h3>
|
|
167
|
+
|
|
168
|
+
<p>Chia complex tasks thành <strong>multiple sequential prompts</strong>, output của prompt trước trở thành input của prompt sau.</p>
|
|
169
|
+
|
|
170
|
+
<pre><code class="language-text">Step 1: "Extract key entities from this document: {doc}"
|
|
171
|
+
→ Output: list of entities
|
|
172
|
+
|
|
173
|
+
Step 2: "For each entity {entities}, find the sentiment
|
|
174
|
+
expressed about it in this text: {doc}"
|
|
175
|
+
→ Output: entity-sentiment pairs
|
|
176
|
+
|
|
177
|
+
Step 3: "Create a summary report of sentiment analysis
|
|
178
|
+
for these entities: {entity_sentiments}"
|
|
179
|
+
→ Output: Final report
|
|
180
|
+
</code></pre>
|
|
181
|
+
|
|
182
|
+
<h2 id="comparison"><strong>5. Comparison Table for Exam</strong></h2>
|
|
183
|
+
|
|
184
|
+
<table>
|
|
185
|
+
<thead><tr><th>Technique</th><th>Examples Given?</th><th>Best For</th><th>Exam Keyword</th></tr></thead>
|
|
186
|
+
<tbody>
|
|
187
|
+
<tr><td><strong>Zero-shot</strong></td><td>None</td><td>Simple, well-known tasks</td><td>"no examples provided"</td></tr>
|
|
188
|
+
<tr><td><strong>One-shot</strong></td><td>1 example</td><td>Setting format with minimal context</td><td>"single example"</td></tr>
|
|
189
|
+
<tr><td><strong>Few-shot</strong></td><td>2-5 examples</td><td>Pattern following, classification</td><td>"examples provided", "demonstrations"</td></tr>
|
|
190
|
+
<tr><td><strong>Chain-of-Thought</strong></td><td>With reasoning steps</td><td>Math, logic, complex reasoning</td><td>"step by step", "reasoning"</td></tr>
|
|
191
|
+
<tr><td><strong>Negative prompting</strong></td><td>N/A</td><td>Avoiding unwanted outputs</td><td>"do not include", "avoid"</td></tr>
|
|
192
|
+
<tr><td><strong>Prompt chaining</strong></td><td>N/A</td><td>Complex multi-step tasks</td><td>"break into steps", "sequential"</td></tr>
|
|
193
|
+
</tbody>
|
|
194
|
+
</table>
|
|
195
|
+
|
|
196
|
+
<h2 id="inference-params"><strong>6. Inference Parameters Review</strong></h2>
|
|
197
|
+
|
|
198
|
+
<p>Prompt engineering cũng bao gồm tuning inference parameters:</p>
|
|
199
|
+
|
|
200
|
+
<table>
|
|
201
|
+
<thead><tr><th>Parameter</th><th>Low Value</th><th>High Value</th></tr></thead>
|
|
202
|
+
<tbody>
|
|
203
|
+
<tr><td><strong>Temperature</strong></td><td>Deterministic, factual (0.0-0.3)</td><td>Creative, diverse (0.7-1.0)</td></tr>
|
|
204
|
+
<tr><td><strong>Top-p</strong></td><td>Focused vocabulary (0.1-0.3)</td><td>Diverse vocabulary (0.9-1.0)</td></tr>
|
|
205
|
+
<tr><td><strong>Top-k</strong></td><td>Limited choices (e.g., 10)</td><td>More choices (e.g., 250)</td></tr>
|
|
206
|
+
<tr><td><strong>Max tokens</strong></td><td>Short responses</td><td>Long responses</td></tr>
|
|
207
|
+
<tr><td><strong>Stop sequences</strong></td><td colspan="2">Define when to stop generating</td></tr>
|
|
208
|
+
</tbody>
|
|
209
|
+
</table>
|
|
210
|
+
|
|
211
|
+
<blockquote>
|
|
212
|
+
<p><strong>Exam tip:</strong> "A customer support chatbot gives inconsistent answers" → Lower <strong>temperature</strong> (closer to 0). "A creative writing app produces boring text" → Raise <strong>temperature</strong> (closer to 1).</p>
|
|
213
|
+
</blockquote>
|
|
214
|
+
|
|
215
|
+
<h2 id="best-practices"><strong>7. Prompt Engineering Best Practices</strong></h2>
|
|
216
|
+
|
|
217
|
+
<ol>
|
|
218
|
+
<li><strong>Be specific</strong>: "Summarize in 3 bullet points" > "Summarize this"</li>
|
|
219
|
+
<li><strong>Provide context</strong>: Include relevant background information</li>
|
|
220
|
+
<li><strong>Define output format</strong>: JSON, markdown, table, bullet points</li>
|
|
221
|
+
<li><strong>Use delimiters</strong>: Separate sections with --- or ``` to avoid prompt injection</li>
|
|
222
|
+
<li><strong>Iterate</strong>: Test and refine prompts based on outputs</li>
|
|
223
|
+
<li><strong>Avoid ambiguity</strong>: Don't assume model knows your intent</li>
|
|
224
|
+
<li><strong>Use examples</strong>: When zero-shot doesn't work, add few-shot examples</li>
|
|
225
|
+
</ol>
|
|
226
|
+
|
|
227
|
+
<h2 id="practice-questions"><strong>8. Practice Questions</strong></h2>
|
|
228
|
+
|
|
229
|
+
<p><strong>Q1:</strong> A developer is working on a classification task, but the model's zero-shot responses are inconsistent. Which prompting technique should the developer try NEXT?</p>
|
|
230
|
+
<ul>
|
|
231
|
+
<li>A) Reduce the temperature to 0</li>
|
|
232
|
+
<li>B) Use few-shot prompting with example inputs and outputs ✓</li>
|
|
233
|
+
<li>C) Fine-tune the model on custom data</li>
|
|
234
|
+
<li>D) Switch to a different model provider</li>
|
|
235
|
+
</ul>
|
|
236
|
+
<p><em>Explanation: Few-shot prompting is the logical next step after zero-shot fails — providing examples helps the model understand the expected pattern. Fine-tuning is more expensive and complex. Temperature adjustment alone may not fix classification logic.</em></p>
|
|
237
|
+
|
|
238
|
+
<p><strong>Q2:</strong> A customer wants their AI application to solve complex mathematical word problems more accurately. Which prompting technique would MOST improve the results?</p>
|
|
239
|
+
<ul>
|
|
240
|
+
<li>A) Zero-shot prompting</li>
|
|
241
|
+
<li>B) Negative prompting</li>
|
|
242
|
+
<li>C) Chain-of-Thought prompting ✓</li>
|
|
243
|
+
<li>D) Prompt chaining</li>
|
|
244
|
+
</ul>
|
|
245
|
+
<p><em>Explanation: Chain-of-Thought prompting encourages the model to show its reasoning step by step, which significantly improves accuracy on mathematical and logical reasoning tasks.</em></p>
|
|
246
|
+
|
|
247
|
+
<p><strong>Q3:</strong> Which of the following is a benefit of using a system prompt in a generative AI application?</p>
|
|
248
|
+
<ul>
|
|
249
|
+
<li>A) It eliminates the need for user input</li>
|
|
250
|
+
<li>B) It reduces the model's inference cost</li>
|
|
251
|
+
<li>C) It defines the model's role, behavior, and constraints ✓</li>
|
|
252
|
+
<li>D) It replaces the need for fine-tuning</li>
|
|
253
|
+
</ul>
|
|
254
|
+
<p><em>Explanation: System prompts set the model's role, behavioral constraints, and output format — establishing consistent behavior across all user interactions without any model training.</em></p>
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: 019c9619-lt01-d3-l06
|
|
3
|
+
title: 'Bài 6: RAG, Vector Databases & Bedrock Knowledge Bases'
|
|
4
|
+
slug: bai-6-rag-vector-databases-knowledge-bases
|
|
5
|
+
description: >-
|
|
6
|
+
Retrieval-Augmented Generation (RAG) architecture.
|
|
7
|
+
Vector databases, embeddings, chunking strategies.
|
|
8
|
+
Amazon Bedrock Knowledge Bases. So sánh RAG vs Fine-tuning.
|
|
9
|
+
duration_minutes: 60
|
|
10
|
+
is_free: true
|
|
11
|
+
video_url: null
|
|
12
|
+
sort_order: 2
|
|
13
|
+
section_title: "Domain 3: Applications of Foundation Models (28%)"
|
|
14
|
+
course:
|
|
15
|
+
id: 019c9619-lt01-7001-c001-lt0100000001
|
|
16
|
+
title: 'Luyện thi AWS Certified AI Practitioner (AIF-C01)'
|
|
17
|
+
slug: luyen-thi-aws-ai-practitioner
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
<div style="text-align: center; margin: 2rem 0;">
|
|
21
|
+
<img src="/storage/uploads/2026/04/aws-aif-bai6-rag-architecture.png" alt="RAG Architecture" style="max-width: 800px; width: 100%; border-radius: 12px;" />
|
|
22
|
+
<p><em>RAG Architecture — Indexing Phase và Query Phase với Amazon Bedrock Knowledge Bases</em></p>
|
|
23
|
+
</div>
|
|
24
|
+
|
|
25
|
+
<h2 id="rag-overview"><strong>1. What is RAG?</strong></h2>
|
|
26
|
+
|
|
27
|
+
<p><strong>Retrieval-Augmented Generation (RAG)</strong> là kỹ thuật kết hợp FM với <strong>external knowledge sources</strong> để trả lời chính xác hơn, giảm hallucination, và cập nhật thông tin mà model chưa biết.</p>
|
|
28
|
+
|
|
29
|
+
<h3 id="why-rag"><strong>1.1. Why RAG?</strong></h3>
|
|
30
|
+
|
|
31
|
+
<table>
|
|
32
|
+
<thead><tr><th>Problem</th><th>RAG Solution</th></tr></thead>
|
|
33
|
+
<tbody>
|
|
34
|
+
<tr><td>Knowledge cutoff date</td><td>Retrieve latest documents</td></tr>
|
|
35
|
+
<tr><td>Hallucination</td><td>Ground responses in real data</td></tr>
|
|
36
|
+
<tr><td>No domain knowledge</td><td>Add company-specific documents</td></tr>
|
|
37
|
+
<tr><td>Generic answers</td><td>Cite specific sources</td></tr>
|
|
38
|
+
<tr><td>Privacy — can't send data to FM training</td><td>Keep data in your own vector DB</td></tr>
|
|
39
|
+
</tbody>
|
|
40
|
+
</table>
|
|
41
|
+
|
|
42
|
+
<h3 id="rag-flow"><strong>1.2. RAG Architecture</strong></h3>
|
|
43
|
+
|
|
44
|
+
<pre><code class="language-text">RAG Pipeline:
|
|
45
|
+
|
|
46
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
47
|
+
│ INDEXING (Done once / periodically) │
|
|
48
|
+
│ │
|
|
49
|
+
│ Documents → Chunking → Embedding Model → Vector Database │
|
|
50
|
+
│ (PDF, web, (split (Amazon Titan (OpenSearch, │
|
|
51
|
+
│ S3, etc.) text) Embeddings) Aurora pgvector)│
|
|
52
|
+
└─────────────────────────────────────────────────────────────┘
|
|
53
|
+
|
|
54
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
55
|
+
│ RETRIEVAL & GENERATION (Per query) │
|
|
56
|
+
│ │
|
|
57
|
+
│ User Query → Embed Query → Search Vector DB → Top-K docs │
|
|
58
|
+
│ │
|
|
59
|
+
│ Augmented Prompt = System Prompt + Retrieved Docs + Query │
|
|
60
|
+
│ │
|
|
61
|
+
│ Augmented Prompt → Foundation Model → Answer with sources │
|
|
62
|
+
└─────────────────────────────────────────────────────────────┘
|
|
63
|
+
</code></pre>
|
|
64
|
+
|
|
65
|
+
<h2 id="chunking"><strong>2. Chunking Strategies</strong></h2>
|
|
66
|
+
|
|
67
|
+
<p>Trước khi tạo embeddings, documents phải được <strong>chia nhỏ (chunked)</strong> thành các đoạn phù hợp.</p>
|
|
68
|
+
|
|
69
|
+
<table>
|
|
70
|
+
<thead><tr><th>Strategy</th><th>Description</th><th>Best For</th></tr></thead>
|
|
71
|
+
<tbody>
|
|
72
|
+
<tr><td><strong>Fixed-size</strong></td><td>Split every N characters/tokens</td><td>Simple, uniform documents</td></tr>
|
|
73
|
+
<tr><td><strong>Sentence-based</strong></td><td>Split at sentence boundaries</td><td>Narrative text</td></tr>
|
|
74
|
+
<tr><td><strong>Paragraph-based</strong></td><td>Split at paragraph breaks</td><td>Well-structured documents</td></tr>
|
|
75
|
+
<tr><td><strong>Semantic</strong></td><td>Split based on topic changes</td><td>Complex documents</td></tr>
|
|
76
|
+
<tr><td><strong>Hierarchical</strong></td><td>Parent-child chunk relationships</td><td>Long documents with sections</td></tr>
|
|
77
|
+
</tbody>
|
|
78
|
+
</table>
|
|
79
|
+
|
|
80
|
+
<h3 id="chunk-size"><strong>Chunk Size Trade-offs:</strong></h3>
|
|
81
|
+
|
|
82
|
+
<pre><code class="language-text">Small chunks (100-200 tokens):
|
|
83
|
+
✓ More precise retrieval
|
|
84
|
+
✗ May lose context
|
|
85
|
+
✗ More chunks to search
|
|
86
|
+
|
|
87
|
+
Large chunks (500-1000 tokens):
|
|
88
|
+
✓ More context preserved
|
|
89
|
+
✗ May include irrelevant info
|
|
90
|
+
✗ Fewer chunks, less granular
|
|
91
|
+
|
|
92
|
+
Overlap (e.g., 20% between chunks):
|
|
93
|
+
✓ Prevents information loss at boundaries
|
|
94
|
+
✗ Increases storage and compute
|
|
95
|
+
</code></pre>
|
|
96
|
+
|
|
97
|
+
<blockquote>
|
|
98
|
+
<p><strong>Exam tip:</strong> "How to improve RAG retrieval accuracy?" → Adjust <strong>chunk size</strong>, add <strong>overlap</strong>, use <strong>semantic chunking</strong>, improve <strong>embedding model</strong>.</p>
|
|
99
|
+
</blockquote>
|
|
100
|
+
|
|
101
|
+
<h2 id="embeddings"><strong>3. Embeddings for RAG</strong></h2>
|
|
102
|
+
|
|
103
|
+
<h3 id="embedding-models"><strong>3.1. AWS Embedding Models</strong></h3>
|
|
104
|
+
|
|
105
|
+
<table>
|
|
106
|
+
<thead><tr><th>Model</th><th>Modality</th><th>Dimensions</th><th>Use Case</th></tr></thead>
|
|
107
|
+
<tbody>
|
|
108
|
+
<tr><td><strong>Amazon Titan Text Embeddings V2</strong></td><td>Text</td><td>256/512/1024</td><td>Semantic search, RAG</td></tr>
|
|
109
|
+
<tr><td><strong>Amazon Titan Multimodal Embeddings</strong></td><td>Text + Image</td><td>256/384/1024</td><td>Cross-modal search</td></tr>
|
|
110
|
+
<tr><td><strong>Cohere Embed</strong></td><td>Text</td><td>1024</td><td>Multilingual search</td></tr>
|
|
111
|
+
</tbody>
|
|
112
|
+
</table>
|
|
113
|
+
|
|
114
|
+
<h3 id="vector-db"><strong>3.2. Vector Databases on AWS</strong></h3>
|
|
115
|
+
|
|
116
|
+
<table>
|
|
117
|
+
<thead><tr><th>Service</th><th>Type</th><th>Key Feature</th></tr></thead>
|
|
118
|
+
<tbody>
|
|
119
|
+
<tr><td><strong>Amazon OpenSearch Serverless</strong></td><td>Managed</td><td>Vector search collection type, serverless</td></tr>
|
|
120
|
+
<tr><td><strong>Amazon Aurora PostgreSQL</strong></td><td>RDB + Vector</td><td>pgvector extension</td></tr>
|
|
121
|
+
<tr><td><strong>Amazon Neptune</strong></td><td>Graph + Vector</td><td>Knowledge graphs with vector search</td></tr>
|
|
122
|
+
<tr><td><strong>Amazon DocumentDB</strong></td><td>Document + Vector</td><td>MongoDB-compatible with vector search</td></tr>
|
|
123
|
+
<tr><td><strong>Amazon MemoryDB</strong></td><td>In-memory + Vector</td><td>Redis-compatible, ultra-low latency</td></tr>
|
|
124
|
+
<tr><td><strong>Pinecone (3rd party)</strong></td><td>Dedicated vector DB</td><td>Popular, integrates with Bedrock</td></tr>
|
|
125
|
+
</tbody>
|
|
126
|
+
</table>
|
|
127
|
+
|
|
128
|
+
<h2 id="bedrock-kb"><strong>4. Amazon Bedrock Knowledge Bases</strong></h2>
|
|
129
|
+
|
|
130
|
+
<p><strong>Bedrock Knowledge Bases</strong> là <strong>fully managed RAG solution</strong>. AWS handles chunking, embedding, indexing, retrieval — bạn chỉ cần point to data sources.</p>
|
|
131
|
+
|
|
132
|
+
<h3 id="kb-architecture"><strong>4.1. How It Works</strong></h3>
|
|
133
|
+
|
|
134
|
+
<pre><code class="language-text">Setup:
|
|
135
|
+
┌───────────┐ ┌───────────────┐ ┌─────────────────┐
|
|
136
|
+
│ S3 Bucket │────→│ Bedrock │────→│ Vector Store │
|
|
137
|
+
│ (docs) │ │ Knowledge Base│ │ (OpenSearch/ │
|
|
138
|
+
│ │ │ (auto-chunk, │ │ Aurora/Pinecone) │
|
|
139
|
+
│ │ │ auto-embed) │ │ │
|
|
140
|
+
└───────────┘ └───────────────┘ └─────────────────┘
|
|
141
|
+
|
|
142
|
+
Query:
|
|
143
|
+
┌───────────┐ ┌───────────────┐ ┌─────────────────┐
|
|
144
|
+
│ User │────→│ Knowledge Base│────→│ FM (Claude, │
|
|
145
|
+
│ "What is │ │ retrieves │ │ Titan, etc.) │
|
|
146
|
+
│ the..." │ │ relevant docs │ │ generates answer │
|
|
147
|
+
└───────────┘ └───────────────┘ └─────────────────┘
|
|
148
|
+
</code></pre>
|
|
149
|
+
|
|
150
|
+
<h3 id="kb-data-sources"><strong>4.2. Supported Data Sources</strong></h3>
|
|
151
|
+
|
|
152
|
+
<ul>
|
|
153
|
+
<li><strong>Amazon S3</strong>: PDF, TXT, MD, HTML, DOC, CSV</li>
|
|
154
|
+
<li><strong>Web Crawler</strong>: Crawl websites automatically</li>
|
|
155
|
+
<li><strong>Confluence</strong>: Atlassian Confluence pages</li>
|
|
156
|
+
<li><strong>SharePoint</strong>: Microsoft SharePoint documents</li>
|
|
157
|
+
<li><strong>Salesforce</strong>: Salesforce knowledge articles</li>
|
|
158
|
+
</ul>
|
|
159
|
+
|
|
160
|
+
<h3 id="kb-features"><strong>4.3. Key Features</strong></h3>
|
|
161
|
+
|
|
162
|
+
<table>
|
|
163
|
+
<thead><tr><th>Feature</th><th>Benefit</th></tr></thead>
|
|
164
|
+
<tbody>
|
|
165
|
+
<tr><td><strong>Managed chunking</strong></td><td>Auto-splits documents (fixed, semantic, hierarchical)</td></tr>
|
|
166
|
+
<tr><td><strong>Auto-sync</strong></td><td>Periodically re-indexes when data changes</td></tr>
|
|
167
|
+
<tr><td><strong>Source attribution</strong></td><td>Returns source documents with answers</td></tr>
|
|
168
|
+
<tr><td><strong>Metadata filtering</strong></td><td>Filter chunks by custom metadata fields</td></tr>
|
|
169
|
+
<tr><td><strong>Hybrid search</strong></td><td>Combines semantic + keyword search</td></tr>
|
|
170
|
+
<tr><td><strong>Guardrails integration</strong></td><td>Apply safety filters to RAG responses</td></tr>
|
|
171
|
+
</tbody>
|
|
172
|
+
</table>
|
|
173
|
+
|
|
174
|
+
<blockquote>
|
|
175
|
+
<p><strong>Exam tip:</strong> "A company wants to build a chatbot that answers questions from internal documents stored in S3, with minimal custom code" → <strong>Amazon Bedrock Knowledge Bases</strong>.</p>
|
|
176
|
+
</blockquote>
|
|
177
|
+
|
|
178
|
+
<h2 id="rag-vs-finetuning"><strong>5. RAG vs Fine-tuning</strong></h2>
|
|
179
|
+
|
|
180
|
+
<table>
|
|
181
|
+
<thead><tr><th>Factor</th><th>RAG</th><th>Fine-tuning</th></tr></thead>
|
|
182
|
+
<tbody>
|
|
183
|
+
<tr><td><strong>Purpose</strong></td><td>Access external/current data</td><td>Teach new skills/domain patterns</td></tr>
|
|
184
|
+
<tr><td><strong>Data freshness</strong></td><td>Always up-to-date</td><td>Fixed at training time</td></tr>
|
|
185
|
+
<tr><td><strong>Training required?</strong></td><td>No model training</td><td>Yes, needs labeled data + compute</td></tr>
|
|
186
|
+
<tr><td><strong>Cost</strong></td><td>Vector DB + retrieval costs</td><td>Training compute + storage</td></tr>
|
|
187
|
+
<tr><td><strong>Hallucination</strong></td><td>Reduced (grounded in data)</td><td>May still hallucinate</td></tr>
|
|
188
|
+
<tr><td><strong>Latency</strong></td><td>Slightly higher (retrieval step)</td><td>Same as base model</td></tr>
|
|
189
|
+
<tr><td><strong>Best for</strong></td><td>Q&A, search, knowledge bases</td><td>Style, tone, domain-specific patterns</td></tr>
|
|
190
|
+
<tr><td><strong>Data privacy</strong></td><td>Data stays in your vector DB</td><td>Data used in training process</td></tr>
|
|
191
|
+
</tbody>
|
|
192
|
+
</table>
|
|
193
|
+
|
|
194
|
+
<h3 id="when-to-use"><strong>Decision Matrix:</strong></h3>
|
|
195
|
+
|
|
196
|
+
<pre><code class="language-text">"Need to answer from company docs?" → RAG
|
|
197
|
+
"Need real-time/latest information?" → RAG
|
|
198
|
+
"Need to change model's writing style?" → Fine-tuning
|
|
199
|
+
"Need model to follow specific format?" → Try prompting first → then fine-tuning
|
|
200
|
+
"Need domain-specific terminology?" → RAG (if in docs) or Fine-tuning (if patterns)
|
|
201
|
+
"Minimum effort/cost?" → RAG > Prompt Engineering > Fine-tuning
|
|
202
|
+
</code></pre>
|
|
203
|
+
|
|
204
|
+
<h2 id="rag-evaluation"><strong>6. Evaluating RAG Quality</strong></h2>
|
|
205
|
+
|
|
206
|
+
<table>
|
|
207
|
+
<thead><tr><th>Metric</th><th>What it measures</th></tr></thead>
|
|
208
|
+
<tbody>
|
|
209
|
+
<tr><td><strong>Faithfulness</strong></td><td>Is the answer grounded in retrieved docs? (no hallucination)</td></tr>
|
|
210
|
+
<tr><td><strong>Relevance</strong></td><td>Are retrieved documents relevant to the query?</td></tr>
|
|
211
|
+
<tr><td><strong>Answer correctness</strong></td><td>Is the final answer factually correct?</td></tr>
|
|
212
|
+
<tr><td><strong>Context precision</strong></td><td>What % of retrieved chunks are actually relevant?</td></tr>
|
|
213
|
+
<tr><td><strong>Context recall</strong></td><td>Did we retrieve all relevant chunks?</td></tr>
|
|
214
|
+
</tbody>
|
|
215
|
+
</table>
|
|
216
|
+
|
|
217
|
+
<h2 id="practice-questions"><strong>7. Practice Questions</strong></h2>
|
|
218
|
+
|
|
219
|
+
<p><strong>Q1:</strong> A healthcare company wants an AI assistant that answers questions from their latest medical research papers stored in Amazon S3. The information changes weekly. Which approach is MOST suitable?</p>
|
|
220
|
+
<ul>
|
|
221
|
+
<li>A) Fine-tune a foundation model on the papers</li>
|
|
222
|
+
<li>B) Use RAG with Amazon Bedrock Knowledge Bases ✓</li>
|
|
223
|
+
<li>C) Use zero-shot prompting with a large context window</li>
|
|
224
|
+
<li>D) Pre-train a custom model on medical data</li>
|
|
225
|
+
</ul>
|
|
226
|
+
<p><em>Explanation: RAG with Bedrock Knowledge Bases is ideal — it automatically indexes S3 documents, retrieves relevant information per query, and keeps responses current without retraining. Weekly updates are handled by auto-sync.</em></p>
|
|
227
|
+
|
|
228
|
+
<p><strong>Q2:</strong> What is the PRIMARY purpose of chunking documents in a RAG pipeline?</p>
|
|
229
|
+
<ul>
|
|
230
|
+
<li>A) To reduce storage costs</li>
|
|
231
|
+
<li>B) To split documents into manageable pieces for embedding and retrieval ✓</li>
|
|
232
|
+
<li>C) To encrypt sensitive data</li>
|
|
233
|
+
<li>D) To convert documents to a different file format</li>
|
|
234
|
+
</ul>
|
|
235
|
+
<p><em>Explanation: Chunking splits large documents into smaller, semantically meaningful pieces that can be individually embedded and retrieved. This enables precise retrieval of relevant information rather than processing entire documents.</em></p>
|
|
236
|
+
|
|
237
|
+
<p><strong>Q3:</strong> A company built a RAG application, but it sometimes returns answers not supported by the retrieved documents. Which metric should they focus on improving?</p>
|
|
238
|
+
<ul>
|
|
239
|
+
<li>A) Context recall</li>
|
|
240
|
+
<li>B) Answer length</li>
|
|
241
|
+
<li>C) Faithfulness ✓</li>
|
|
242
|
+
<li>D) Response latency</li>
|
|
243
|
+
</ul>
|
|
244
|
+
<p><em>Explanation: Faithfulness measures whether the generated answer is grounded in the retrieved documents. Low faithfulness means the model is generating information beyond what the retrieved context supports (hallucination in RAG context).</em></p>
|