3.1 KiB
3.1 KiB
LightRAG Prompts
Thư mục này chứa tất cả các prompt templates được sử dụng trong LightRAG.
Cấu trúc
Các prompts được tổ chức thành các file text riêng biệt thay vì hardcode trong Python code:
Main Prompts
entity_extraction_system_prompt.md- System prompt cho entity extractionentity_extraction_user_prompt.md- User prompt cho entity extractionentity_continue_extraction_user_prompt.md- Prompt để tiếp tục extractionsummarize_entity_descriptions.md- Prompt để tổng hợp entity descriptionsfail_response.md- Response khi không tìm thấy contextrag_response.md- Prompt cho RAG response với knowledge graphnaive_rag_response.md- Prompt cho naive RAG responsekg_query_context.md- Template cho knowledge graph query contextnaive_query_context.md- Template cho naive query contextkeywords_extraction.md- Prompt cho keyword extraction
Examples
entity_extraction_example_1.md- Ví dụ 1: Narrative textentity_extraction_example_2.md- Ví dụ 2: Financial/market dataentity_extraction_example_3.md- Ví dụ 3: Sports eventkeywords_extraction_example_1.md- Ví dụ về international tradekeywords_extraction_example_2.md- Ví dụ về deforestationkeywords_extraction_example_3.md- Ví dụ về education
Cách sử dụng
Các prompts được load tự động khi import module lightrag.prompt:
from lightrag.prompt import PROMPTS
# Truy cập prompt
system_prompt = PROMPTS["entity_extraction_system_prompt"]
# Format với parameters
formatted = system_prompt.format(
entity_types="person, organization, location",
tuple_delimiter="<|#|>",
language="English",
# ...
)
Chỉnh sửa Prompts
Để chỉnh sửa prompts:
- Mở file
.mdtương ứng trong thư mục này - Chỉnh sửa nội dung (giữ nguyên các placeholder như
{entity_types},{language}, etc.) - Lưu file
- Khởi động lại application để load prompt mới
Lưu ý:
- Các placeholder trong dấu ngoặc nhọn
{}sẽ được thay thế bằng giá trị thực tế khi runtime. Không xóa hoặc đổi tên các placeholder này trừ khi bạn cũng cập nhật code tương ứng. - File format là Markdown (
.md) để hỗ trợ syntax highlighting và format đẹp hơn trong editors.
Lợi ích của việc tách prompts ra file riêng
- Dễ chỉnh sửa: Không cần chạm vào Python code để thay đổi prompts
- Version control: Dễ dàng track changes trong prompts
- Collaboration: Người không biết code có thể chỉnh sửa prompts
- Testing: Có thể test nhiều phiên bản prompts khác nhau
- Reusability: Prompts có thể được sử dụng bởi các công cụ khác
- Maintainability: Code Python gọn gàng hơn, dễ maintain hơn
Backward Compatibility
Cấu trúc PROMPTS dictionary được giữ nguyên 100% như cũ, nên tất cả code hiện tại vẫn hoạt động bình thường mà không cần thay đổi gì.