Chatbot sử dụng kỹ thuật Retrieval Augmented Generation (RAG) để trả lời câu hỏi về Pittsburgh / Carnegie Mellon University (CMU) và VNU. Hệ thống sử dụng:
- Together AI API cho Large Language Model (LLM) : meta-llama/Llama-3.3-70B-Instruct-Turbo-Free
- Hugging Face cho Embedding Model : intfloat/multilingual-e5-large-instruct
- ChromaDB làm vector database
- Python 3.8+
- CUDA (tùy chọn, để tăng tốc embedding)
- Token từ Together AI và Hugging Face (xem phần "Đăng ký và lấy API Token" bên dưới)
- Truy cập Together AI
- Đăng ký tài khoản mới
- Vào Dashboard
- Tạo API key mới và lưu lại
- Truy cập Hugging Face
- Đăng ký tài khoản mới
- Vào Settings > Access Tokens
- Tạo token mới với quyền "read"
- Clone repository:
git clone https://github.com/CTNone/RAG_NLP_build_- Cài đặt các thư viện:
pip install -r requirements.txtĐể bắt đầu nhanh:
- Tải bộ dữ liệu mẫu: Google Drive
Hoặc tự chuẩn bị dữ liệu theo hướng dẫn bên dưới
Các folder dữ liệu thường được bắt đầu bằng "DATA_" và có folder "segmented" như sau:
data/
├── DATA_CMU_Pit/
│ └── segmented/
│ ├── about_cmu.json
│ ├── campus_life.json
│ └── ...
├── ...
Mỗi file JSON trong thư mục segmented/ phải có cấu trúc sau:
{
"url": "https://example.com/source-page",
"title": "Tiêu đề trang",
"chunks": [
"Đoạn văn bản thứ nhất...",
"Đoạn văn bản thứ hai...",
"Đoạn văn bản thứ ba..."
]
}Tùy chỉnh nội dung file config.yaml sao cho phù hợp:
Nếu muốn tùy chỉnh embedding nhanh hơn hoặc phù hợp cấu hình máy tính. Hãy thử một số model embedding sau:
- sentence-transformers/all-MiniLM-L6-v2 (22.7M params)
- BAAI/bge-small-en-v1.5 (33.4M params)
- BAAI/bge-base-en-v1.5 (109M params)
- sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2 (118M params)
- BAAI/bge-m3
- ... Hoặc giữ nguyên Model intfloat/multilingual-e5-large (560M params)
# API Credentials
api:
huggingface:
token: "your-huggingface-token" # Token từ Hugging Face
embedding_model: "sentence-transformers/all-MiniLM-L6-v2"
together:
token: "your-together-token" # Token từ Together AI
model_id: "meta-llama/Llama-3.3-70B-Instruct-Turbo-Free"
# Database
db_dir: "chroma_db"
# Data Paths
data_path: "data" # Folder chứa các dữ liệu cần thiết
data_prefix: "DATA_" # Prefix để tự động tìm các thư mục dữ liệu
# Test Questions and Answers Paths
test_questions_dir: "data/test_questions"
test_answers_dir: "data/test_answers"
# Model Parameters
max_new_tokens: Số lượng token tối đa mà model có thể sinh ra trong câu trả lời
temperature: Độ ngẫu nhiên trong câu trả lời (0.0-1.0, càng thấp càng ổn định)
top_p: Ngưỡng xác suất tích lũy để chọn token tiếp theo (0.0-1.0)
repetition_penalty: Hệ số phạt cho việc lặp lại từ/cụm từ (>1.0 để giảm lặp lại)
# RAG Settings
retriever_k: Số lượng đoạn văn bản truy xuất cho mỗi câu hỏi
# Prompt Template
template:python create_chroma_db.pypython app.py- Mở trình duyệt và truy cập địa chỉ hiển thị trong terminal (thường là http://127.0.0.1:7860)
- Bắt đầu đặt câu hỏi về Pittsburgh / CMU và VNU!