Vì sao RAG trả về sai đoạn văn?
Chunking: kích thước chunk, phần chồng lấn và chỗ cắt trong RAG · Thực hành · 5 phút · rag, embeddings · học sau Tìm kiếm ngữ nghĩa: embedding và độ tương đồng cosine
RAG cắt tài liệu thành các chunk (mẩu) và trả về chunk có embedding chỉ gần câu hỏi nhất. Chỗ cắt quyết định chunk đó có chứa câu trả lời hay không: cắt giữa một ý sẽ tạo ra chunk nghe có vẻ đúng nhưng thiếu câu trả lời.
1 Đoán trước
2 Xem
Where the cuts fall
1 / 4ask:“How many requests per day does the free plan allow?”
Every account starts on the Free plan.
The Pro plan costs $20 a month, billed in advance. It allows 50,000 requests per day, and support answers within four hours.
The Free plan needs no card: sign up with an email address and your API key appears at once. It allows 1,000 requests per day.
Requests over the daily limit return error 429 until midnight UTC, when the counter resets. Unused requests do not roll over.
Team plans start at five seats. Each seat adds 10,000 requests per day to a shared pool.
5 chunks · the search returns the lit one, score 0.75: the answer, “1,000”, is not in it ✗
- ✗ requests per day, and support answers within four hours. The Free plan needs no card: sign up with an email0.75
- ✓ address and your API key appears at once. It allows 1,000 requests per day. Requests over the daily limit return0.64
- ✗ Every account starts on the Free plan. The Pro plan costs $20 a month, billed in advance. It allows 50,0000.57
measured with all-MiniLM-L6-v2 (384 numbers per chunk) · cosine similarity · 2026-10-23
Cut every 20 words: the free-plan question gets a chunk with neither number. Drag the size.
Bộ tìm kiếm trả về chunk nghe giống câu hỏi nhất; nếu chỗ cắt chia đôi một ý, chunk đó có thể nghe đúng mà chẳng chứa gì.
Ứng dụng RAG không thể embed cả một cuốn hướng dẫn thành một vector, nên nó cắt tài liệu thành các chunk, embed từng chunk, rồi dán vài chunk gần nhất vào prompt. Bộ tìm kiếm chấm điểm một chunk *nghe giống* câu hỏi đến đâu, không phải nó có trả lời câu hỏi hay không. Chỗ cắt quyết định một chunk nói về điều gì.
4 Bạn là model
Bạn là bộ tìm kiếm. Với bốn câu hỏi, mỗi câu trên trang được cắt theo một cách khác nhau, hãy chọn chunk mà all-MiniLM-L6-v2 chấm điểm cao nhất.
you are the search · pick the chunk all-MiniLM-L6-v2 scores highest
“When does the daily request limit reset?” · cut every 20 words
measured with all-MiniLM-L6-v2 (384 numbers per chunk) · cosine similarity · 2026-10-23
You are the search. Which chunk scores highest?5 Kiểm tra
Vài thói quen giúp ích. Cắt theo cấu trúc sẵn có của tài liệu: tiêu đề, đoạn văn, câu. Mỗi chunk một ý, thêm chút chồng lấn (overlap) cho những ý chạy qua chỗ cắt. Thêm tiêu đề hoặc mục vào mỗi chunk; thử nghiệm của Anthropic giảm 35% số lần tìm sai nhờ cách đó. Rồi thử bằng câu hỏi thật: chunk đứng đầu có chứa câu trả lời không?
7 Nói lại bằng lời bạn
8 Nhiệm vụ · 5 phút
Chép key miễn phí trên trang embeddings của Jina (không cần thẻ) và embed ba đoạn văn trong một request với "normalized": true: câu hỏi “How many requests per day does the free plan allow?”, mẩu 20 từ “requests per day, and support answers within four hours. The Free plan needs no card: sign up with an email”, và đoạn văn “The Free plan needs no card: sign up with an email address and your API key appears at once. It allows 1,000 requests per day.” Nhân vô hướng (dot) từng cái với câu hỏi. Mô hình lớn hơn có mắc cùng lỗi không?
Ba câu nhanh
Rút ngẫu nhiên từ bộ câu hỏi của bài; lần sau sẽ khác.
Xong chưa?
Nhận email khi có bài mới
Bài mới nằm trong bản tin hằng tuần, chỉ gửi vào tuần có bài. Bạn xác nhận qua email trước; hủy đăng ký chỉ với một lần bấm.
Đọc thêm
Nguồn
- Cosine similarities measured with sentence-transformers/all-MiniLM-L6-v2 (https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2: 384 dimensions, mean pooling, normalised, max 256 word pieces) on 2026-10-23 by scripts/explain-data/chunking.ts, which reuses the plain forward pass of scripts/explain-data/semantic-search.ts (it reproduces the published sbert.net example 0.6660, 0.1046, 0.1411)
- The pricing page (92 words, 5 paragraphs, a made-up API) and the three questions were written for the lesson; the cuts are computed by app/components/explain/lessons/chunking-data.ts, the same code the picture uses
- Scores used: 20 words, free plan → mixed Pro/Free chunk 0.753, chunk with 1,000 0.637, first chunk 0.572; 20 words, reset → 1,000 chunk 0.689, midnight chunk 0.507; 20 words + 10 overlap, reset → 0.784 (holds the answer), free → 0.753 (mixed chunk again); 10 words, Pro price → “Every account … The Pro plan” 0.654, “costs $20 …” 0.511; by sentence, free → “It allows 1,000 requests per day.” 0.759, “It allows 50,000 …” 0.680; by paragraph → free 0.780, reset 0.784, Pro 0.836; whole page → free 0.764, reset 0.413, Pro 0.766
- https://www.anthropic.com/news/contextual-retrieval (Sep 19, 2024, checked 2026-10-23): Contextual Embeddings cut the top-20 retrieval failure rate by 35% (5.7% → 3.7%); with Contextual BM25 by 49%; “The choice of chunk size, chunk boundary, and chunk overlap can affect retrieval performance”
- https://jina.ai/embeddings/ (checked 2026-10-23): new users get an auto-generated API key with free tokens; endpoint https://api.jina.ai/v1/embeddings; aifree.dev catalog jina-ai-free-api-tokens (verified 2026-10-12): 10M tokens per new API key, no card
Đăng Oct 23, 2026 · cập nhật Oct 23, 2026