Exam Tip: Token optimization là chủ đề quan trọng. Nhớ rằng chi phí GenAI tính theo tokens (input + output). Giảm tokens = giảm chi phí.
Kiến thức cần nắm:
Giải thích chi tiết:
Token Cost Structure:
Total Cost = (Input Tokens × Input Price) + (Output Tokens × Output Price)
Optimization Techniques:
| Technique | Mô tả | Tiết kiệm |
|---|---|---|
| Prompt compression | Loại bỏ text thừa trong prompt | 20-40% input tokens |
| Context pruning | Chỉ include relevant context trong RAG | 30-50% input tokens |
| Response limiting | Set max_tokens phù hợp | Control output cost |
| System prompt caching | Cache system prompts dài | Giảm repeated input cost |
| Summarization | Summarize long documents trước khi đưa vào context | 50-70% input tokens |
Ví dụ Context Pruning cho RAG:
# Thay vì đưa toàn bộ 10 retrieved chunks
# Chỉ đưa top-3 relevant chunks
retrieved_docs = knowledge_base.retrieve(
query=user_query,
retrievalConfiguration={
'vectorSearchConfiguration': {
'numberOfResults': 3 # Limit to top 3
}
}
)
Kiến thức cần nắm:
Giải thích chi tiết:
Model Tiering Strategy:
| Tier | Model | Use Case | Cost |
|---|---|---|---|
| Tier 1 (Simple) | Haiku, Titan Lite | Classification, extraction | Thấp nhất |
| Tier 2 (Standard) | Sonnet, Titan Express | Summarization, Q&A | Trung bình |
| Tier 3 (Complex) | Opus, large models | Complex reasoning, analysis | Cao nhất |
Decision Framework:
Kiến thức cần nắm:
Giải thích chi tiết:
Provisioned Throughput trong Bedrock:
Batch Inference:
Kiến thức cần nắm:
Giải thích chi tiết:
Caching Strategies:
| Strategy | Implementation | Best For |
|---|---|---|
| Exact match cache | DynamoDB/ElastiCache | Identical queries |
| Semantic cache | Vector similarity search | Similar queries |
| Prompt caching | Bedrock native feature | Repeated system prompts |
| Edge caching | CloudFront | Static/semi-static responses |
Semantic Caching Flow:
User Query → Embed query → Search cache (vector similarity)
↓
Cache hit (similarity > threshold) → Return cached response
↓
Cache miss → Call FM → Store response in cache → Return
Prompt Caching trong Bedrock cho phép cache phần system prompt hoặc context dài. Khi nhiều requests share cùng system prompt, chỉ cần gửi 1 lần và cache lại, giảm đáng kể input token cost.