Trực quan hoá chunking RAG
Xem tài liệu được cắt thành các chunk cho RAG thế nào: kích thước, overlap, số token, chi phí embedding và context được truy xuất
Tài liệu
Tương tự RecursiveCharacterTextSplitter của LangChain: ưu tiên cắt ở dòng trống trước, sau đó xuống dòng, câu rồi tới từ để giữ ngữ nghĩa tốt nhất.
Mẫu cấu hình (kích thước / overlap):
- Số chunk
- 3
- Token tài liệu
- 232
- Token TB / chunk
- 81
- Token nhỏ nhất / lớn nhất
- 46 / 126
- Tổng token cần embed
- 242
- Hệ số chồng lấp
- 1.04×
Chi phí embedding ước tính: $0.000005
Ngữ cảnh đưa vào mỗi prompt: 323 token
Bản đồ tài liệu (màu vàng = phần chồng lấp với chunk trước)
Các hàng xen kẽ giúp dễ phân biệt những chunk liền kề.
- #170 token280 ký tự0–280
# Retrieval-Augmented Generation Retrieval-Augmented Generation (RAG) gives a language model access to knowledge it was not trained on. Instead of fine-tuning, you split your documents into chunks, embed each chunk, and store the vectors in a database. ## Why chunking matters
- #2126 token503 ký tự255–758Chồng lấp 25 ký tự
## Why chunking matters At query time the question is embedded and the closest chunks are retrieved. If a chunk is too large, it dilutes the meaning and wastes context window. If it is too small, it loses the surrounding context and the answer gets cut in half. A common starting point is 256 to 512 tokens with 10 to 20 percent overlap. Overlap repeats the end of one chunk at the start of the next, so a sentence that straddles a boundary is still found whole in at least one chunk. ## Trade-offs
- #346 token184 ký tự743–927Chồng lấp 15 ký tự
## Trade-offs Larger overlap improves recall but increases the number of tokens you embed and store. Always measure retrieval quality on your own questions before settling on a size.
Số lượng token là ước tính (~4 ký tự/token với tiếng Anh, ~1 ký tự/token với chữ phi Latinh), không phải kết quả chính xác từ tokenizer của từng mô hình. Chi phí thực tế phụ thuộc bảng giá hiện hành của nhà cung cấp.