Context Window: Giới Hạn Tối Quan Trọng
Nếu bạn chỉ nhớ được một điều từ khóa học này, hãy nhớ: Context Window là giới hạn "trí nhớ" của AI. Hiểu và quản lý nó là skill phân biệt giữa người dùng AI hiệu quả và người thất vọng với AI.
Context Window Là Gì?
Context Window = số lượng tokens (≈ từ/ký tự) mà AI có thể "nhìn thấy" cùng lúc. Bao gồm:
- Prompt của bạn
- Files được include
- Conversation history
- AI response đang generate
Token Limits Phổ Biến:
| Model | Context Window |
|---|---|
| Claude 3.5 Sonnet | 200K tokens |
| GPT-4o | 128K tokens |
| Cursor Tab | 4K tokens |
| Windsurf Cascade | 100K+ tokens |
Tại Sao Điều Này Quan Trọng?
Vấn đề 1: Thông tin bị cắt
Bạn include 10 files lớn + prompt dài
→ AI chỉ "nhớ" được phần đầu
→ Bỏ lỡ context quan trọng ở cuối
→ Output sai hoặc không đầy đủ
Vấn đề 2: Conversation drift
Chat dài với AI
→ Context đầy dần
→ AI "quên" instructions ban đầu
→ Behavior thay đổi bất thường
Vấn đề 3: Cost explosion
Tokens nhiều = tiền nhiều
Mỗi message include whole codebase
→ Bill cuối tháng shock
Cursor Context Features
1. @-mentions:
@file- include specific file@folder- include folder contents@codebase- search across codebase@docs- reference documentation
2. .cursorules file: Định nghĩa context rules cho dự án:
# .cursorrules
Always follow TypeScript strict mode
Use Tailwind for styling, no inline styles
Prefer server components over client
Reference: https://docs.project.com
3. Notepads: Lưu trữ reusable context snippets cho common tasks.
Windsurf Context Features
1. Cascade Flow: AI tự động phân tích dependencies và include relevant files.
2. Context Pinning: Ghim important files vào context permanently.
3. Workspace Indexing: Full codebase được index và searchable.
Best Practices Quản Lý Context
| Practice | Benefit |
|---|---|
| Start fresh chats | Clean context, precise outputs |
| Include only relevant files | Reduce noise, save tokens |
| Use .cursorrules | Consistent behavior across sessions |
| Reference instead of paste | AI fetches what it needs |
| Summary checkpoints | Recap progress periodically |
Pro Tips Production
- "Forgetful AI" trick: Paste lại instructions quan trọng khi chat dài
- Context budget: Dành 30% cho response, 70% cho input
- Selective inclusion:
@filespecific functions, không whole file - Clean conversation: New chat mỗi khi đổi task
🔥 Golden Rule: Treat context window như RAM - limited và precious. Garbage in, garbage out.
Bài Tập
Thử nghiệm: Cho cùng một prompt, so sánh output khi include 1 file vs 10 files. Observe quality difference.
