Extending AI Knowledge: Docs & Indexing
AI models được train trên data cũ. Cursor cutoff có thể là 2023. Libraries update liên tục. Vậy làm sao để AI biết về latest APIs và your specific codebase patterns?
The Knowledge Gap Problem
Scenario phổ biến:
Bạn: "Implement server action với Next.js 14"
AI: *Generates outdated API syntax*
Bạn: "Đây không đúng, Next.js 14 dùng syntax khác"
AI: "Xin lỗi, tôi không có thông tin mới nhất..."
Solution 1: @docs - Documentation Integration
Cursor hỗ trợ index docs từ URLs:
Settings → Features → Docs
Add: https://nextjs.org/docs
Add: https://ui.shadcn.com
Add: https://supabase.com/docs
Usage trong prompt:
@docs Next.js Server Actions
Implement form submission với server action
theo đúng Next.js 14 documentation
Solution 2: Codebase Indexing
Cursor Codebase Indexing:
- Tự động index toàn bộ project
- Semantic search across files
- Understand code relationships
Enable: Settings → Features → Codebase Indexing → On
Usage:
@codebase find all usages of useAuth hook
@codebase how is error handling done in API routes
Solution 3: Custom Knowledge Base
Tạo project-specific docs:
docs/
├── ARCHITECTURE.md # System design decisions
├── CONVENTIONS.md # Coding standards
├── API_PATTERNS.md # How to write APIs
└── COMPONENT_GUIDE.md # UI component patterns
Reference trong prompts:
@file docs/CONVENTIONS.md
Create new API route following our patterns
Solution 4: .cursorrules Deep Dive
# .cursorrules
## Project Context
This is a Next.js 14 SaaS application for education.
Tech stack: Next.js, Supabase, Tailwind, Shadcn/ui
## Coding Standards
- Use TypeScript strict mode
- Prefer server components
- Use Zod for validation
- Error messages in Vietnamese
## API Patterns
- All API routes use try-catch
- Return standardized error format
- Log errors to Sentry
## Component Patterns
- Use compound component pattern for complex UI
- Co-locate styles with components
- Extract hooks for reusable logic
## File References
- See @file docs/API_PATTERNS.md for API examples
- See @file docs/CONVENTIONS.md for full standards
Indexing Cho Different Scenarios
Internal Libraries:
Bạn có shared component library?
Index nó trong Cursor để AI hiểu:
@folder packages/ui-kit
"Use Button từ ui-kit, không tạo mới"
Third-party với Custom Config:
@docs Tailwind CSS
@file tailwind.config.ts
"Add responsive variant cho custom breakpoint 'tablet'"
Legacy Code Migration:
@folder legacy/old-components
@folder new-components
"Migrate OldButton thành pattern như NewButton"
Pro Tips For Knowledge Management
| Tip | Implementation |
|---|---|
| Version your docs | Git track CONVENTIONS.md |
| Update after learning | Add new patterns discovered |
| Team alignment | Share .cursorrules across team |
| External docs priority | Add most-used libs to @docs first |
Windsurf Specific: Memories
Windsurf có feature Memories lưu context across sessions:
- Project preferences
- Common patterns
- Past learnings
🔥 Power User Move: Sau mỗi project, update .cursorrules với lessons learned. Knowledge compounds over time.
Bài Tập
- Setup @docs cho 3 libraries bạn dùng nhiều nhất
- Tạo file CONVENTIONS.md cho dự án của bạn
- Viết .cursorrules file với ít nhất 10 rules
