Kiến thức sống ở đâu?Where does the knowledge live?
Fine-tune dạy model nói thế nào. Truy hồi quyết định model nói về cái gì.Fine-tuning teaches a model how to speak. Retrieval decides what it speaks about.
Nét đứt chạy = nội dung phải gửi lại ở mỗi request. Nét liền = đã nằm trong trọng số.Marching dashes = content resent on every request. Solid bar = already inside the weights.
Gộp từ hai đồ hoạ của HackProduct. Thứ tự bên dưới là thứ tự bạn nên đọc: xác định baseline trước, rồi mới đến phần tra cứu chi tiết.Merged from two HackProduct graphics. The order below is the order to read in: settle the baseline first, then use the rest as reference.
Chọn cái nàoWhich one to choose
Phần này dùng hằng ngày. Phần tra cứu chi tiết nằm bên dưới.This is the part you use daily. The reference cards come after it.
không màu = không công cụno colour = no tool
Trước hết: có thể không dùng gì cả không?First: can you use none of them?
Nếu kiến thức riêng của bạn gói gọn dưới ~30 trang, đổi vài lần một tháng, và bạn cần model trả lời đúng chứ chưa cần một khuôn cứng — bạn chưa cần bất kỳ thứ gì trong ba lựa chọn kia. Thử theo thứ tự:If your private knowledge fits in about 30 pages, changes a few times a month, and you need correct answers rather than a rigid house format, you need none of the three. Try these in order:
Viết lại system prompt cho tử tế. Vai trò, ràng buộc, định dạng, điều cấm. Phần lớn "model trả lời lung tung" là prompt mơ hồ, không phải thiếu kiến thức.Write a serious system prompt. Role, constraints, output format, hard prohibitions. Most "the model answers badly" traces to a vague prompt, not missing knowledge.
Few-shot. Ba đến năm cặp mẫu. Ở quy mô nhỏ, nó cạnh tranh trực tiếp với fine-tune.Few-shot. Three to five example pairs. At small scale this competes directly with fine-tuning.
Prompt caching. Phần đầu prompt lặp lại thì bật cache: rẻ hơn khoảng mười lần, nhanh hơn rõ rệt.Prompt caching. If the prompt prefix repeats, cache it: roughly ten times cheaper and noticeably faster.
Bơm dữ liệu bằng code thường. Biết chắc cần bản ghi nào thì SELECT rồi dán vào prompt. Đó không phải RAG, và nó chính xác hơn RAG trong mọi trường hợp bạn biết trước cần lấy gì.Fetch data with ordinary code. If you know which record you need, run the SELECT and paste it in. That is not RAG, and it beats RAG whenever you know in advance what to fetch.
Vượt baseline khi: prompt phình quá cửa sổ ngữ cảnh, hoặc bạn không biết trước cần lấy đoạn nào, hoặc few-shot đã 20 ví dụ mà đầu ra vẫn không ổn định.You have outgrown it when: the prompt no longer fits the window, or you cannot know in advance which passage a question needs, or 20 few-shot examples still give unstable output.
Kiến thức bạn cần thêm là SỰ THẬT hay HÀNH VI?
│
├─ SỰ THẬT
│ │
│ ├─ Nhét vừa cửa sổ ngữ cảnh và ổn định (< ~50 trang)?
│ │ ├─ Có ─▶ Biết trước cần lấy đoạn nào?
│ │ │ ├─ Có ─▶ BASELINE: query bằng code, dán vào prompt
│ │ │ └─ Không ─▶ LONG CONTEXT (bật prompt caching)
│ │ └─ Không ─▶ Kho lớn, đổi thường xuyên, cần trích nguồn?
│ │ ├─ Có ─▶ RAG
│ │ └─ Không ─▶ Cắt nhỏ bài toán, quay lại nhánh trên
│ │
│ └─ Phải trả lời "theo tài liệu nào" ─▶ RAG (bắt buộc)
│
└─ HÀNH VI
│
├─ Đã thử few-shot chưa? ─▶ Chưa ─▶ Quay lại BASELINE
│
├─ Có ≥ 500 ví dụ chất lượng, đã kiểm tay?
│ ├─ Không ─▶ Đi gom dữ liệu trước. Fine-tune 100 ví dụ rác
│ │ chỉ làm model tệ đi theo cách khó gỡ.
│ └─ Có ─▶ Cần giảm chi phí/độ trễ hay chạy offline?
│ ├─ Có ─▶ LoRA / QLoRA
│ └─ Không ─▶ Vẫn LoRA. Full fine-tune chỉ khi đổi cả domain.
│
└─ Vừa cần hành vi vừa cần sự thật ─▶ FINE-TUNE + RAG.
Đây là cấu hình production phổ biến nhất, không phải ngoại lệ.
Is the knowledge you need to add a FACT or a BEHAVIOR?
│
├─ FACT
│ │
│ ├─ Fits the context window and stays stable (< ~50 pages)?
│ │ ├─ Yes ─▶ Do you know in advance which part you need?
│ │ │ ├─ Yes ─▶ BASELINE: query in code, paste into prompt
│ │ │ └─ No ──▶ LONG CONTEXT (turn on prompt caching)
│ │ └─ No ──▶ Large corpus, changes often, needs citations?
│ │ ├─ Yes ─▶ RAG
│ │ └─ No ──▶ Narrow the problem, return to the branch above
│ │
│ └─ Answers must say "according to which document" ─▶ RAG (mandatory)
│
└─ BEHAVIOR
│
├─ Have you tried few-shot? ─▶ No ─▶ Back to BASELINE
│
├─ Do you have ≥ 500 quality examples, reviewed by hand?
│ ├─ No ──▶ Go collect data first. Fine-tuning on 100 junk
│ │ examples only makes the model worse in ways
│ │ that are hard to undo.
│ └─ Yes ─▶ Do you need lower cost/latency, or offline operation?
│ ├─ Yes ─▶ LoRA / QLoRA
│ └─ No ──▶ Still LoRA. Full tuning is for domain shifts.
│
└─ You need behavior AND facts ─▶ FINE-TUNE + RAG.
This is the most common production setup, not an edge case.
Tra cứu chi tiếtReference
Mỗi thẻ: sơ đồ, một câu tóm tắt, dùng cho gì, được gì, mất gì — và câu đánh đổi tách riêng.Each card: diagram, one-line summary, what it is for, what you gain, what you lose — with the trade-off set apart.
01
Long context
nơi đặt kiến thứcknowledge home●○○
Nạp nguyên tài liệu vào prompt, mỗi lần gọi nạp lại từ đầu. Không hạ tầng, không bước chuẩn bị.Load the whole document into the prompt, reloaded from scratch every call. No infrastructure, no preparation step.
tài liệu ┌──── cửa sổ ngữ cảnh ────┐
┌────────┐ │ system prompt │
│ ▔▔▔▔▔▔ │ ┄┄▶ │ TOÀN BỘ tài liệu │ ──▶ LLM ──▶ trả lời
│ ▔▔▔▔▔▔ │ │ câu hỏi │
└────────┘ └─────────────────────────┘
nạp lại mỗi lần gọi
document ┌──── context window ─────┐
┌────────┐ │ system prompt │
│ ▔▔▔▔▔▔ │ ┄┄▶ │ THE ENTIRE document │ ──▶ LLM ──▶ answer
│ ▔▔▔▔▔▔ │ │ question │
└────────┘ └─────────────────────────┘
reloaded on every call
dùng chouse for
Hỏi đáp trên một hợp đồng, hồ sơ thầu
Review pull request, file mã nguồn dài
Tóm tắt biên bản, transcript
Dịch dài cần giữ thuật ngữ nhất quán
Q&A over one contract or tender package
Reviewing a PR or a long source file
Summarizing minutes and transcripts
Long translation with consistent terminology
đượcyou gain
Vài giờ là có bản chạy được
Không index, không job đồng bộ
Không mất thông tin do cắt chunk
Caching giảm ~90% phần lặp lại
A working version in hours
No index, no sync jobs
Nothing lost to a chunk boundary
Caching cuts the repeated part ~90%
mấtyou lose
Chi phí tỉ lệ thẳng với số request
Độ trễ tăng theo độ dài prompt
Mất chú ý ở giữa prompt dài
Trần cứng: vượt cửa sổ là lỗi
Cost scales directly with volume
Latency grows with prompt length
Attention thins in the middle
Hard ceiling: overflow is an error
đánh đổitrade-off
Chọn long context là đổi chi phí lặp lại mãi mãi trên từng request lấy việc không phải xây và vận hành bất kỳ hạ tầng nào.Choosing long context trades a per-request cost that repeats forever for never having to build or run any infrastructure.
Dấu hiệu nhận biết: một người dùng, một tài liệu, một phiên — và tài liệu đó do người dùng đưa vào chứ không phải bạn lưu sẵn.How to recognize it: one user, one document, one session — and the document came from the user rather than your storage.
02
RAG
nơi đặt kiến thứcknowledge home●●○
Kiến thức nằm ngoài model. Có câu hỏi thì đi tìm vài mẩu liên quan nhất và chỉ nhét chừng đó vào prompt.Knowledge stays outside the model. On each question, fetch the most relevant fragments and send only those.
Chọn RAG là đổi một tầng hạ tầng luôn có thể tìm sai và cần đo lường riêng lấy kiến thức luôn tươi, có nguồn, không phụ thuộc kích thước kho.Choosing RAG trades an infrastructure layer that can always retrieve the wrong thing and needs its own metrics for knowledge that stays fresh, cited, and independent of corpus size.
Dấu hiệu nhận biết: kho lớn hơn cửa sổ ngữ cảnh, đổi thường xuyên, và người dùng có quyền hỏi "câu này lấy ở đâu ra".How to recognize it: the corpus exceeds the context window, changes often, and users are entitled to ask where an answer came from.
03
Fine-tune
nơi đặt kiến thứcknowledge home●●●
Huấn luyện tiếp trên ví dụ của bạn để hành vi được ghi thẳng vào trọng số. Model học dáng câu trả lời, không học thuộc nội dung.Continue training on your examples so the behavior lands in the weights. The model learns the shape of your answers, not their content.
ví dụ đã tuyển ─┄▶ huấn luyện ─┄▶ MODEL MỚI ──▶ trả lời
(1k–100k cặp) (một lần, offline) ▲
│
muốn đổi hành vi ─┘ huấn luyện lại
curated examples ─┄▶ training ─┄▶ NEW MODEL ──▶ answer
(1k–100k pairs) (one-time, offline) ▲
│
want new behavior ────┘ retrain
dùng chouse for
Giọng thương hiệu cố định ở quy mô lớn
Đầu ra cứng: luôn đúng schema JSON
Model nhỏ bắt chước model lớn, cắt 5–20× chi phí
Định tuyến, phân loại cần độ trễ < 100ms
A fixed brand voice at scale
Rigid output: always schema-valid JSON
Small model imitating a large one, 5–20× cheaper
Routing and classification under 100ms
đượcyou gain
Prompt ngắn lại ⇒ rẻ và nhanh hơn
Ổn định ở đuôi phân phối, nơi few-shot gãy
Chạy được offline, trong mạng nội bộ
Dạy được thứ khó viết thành lời
Much shorter prompts, cheaper and faster
Holds up in the tail where few-shot breaks
Runs offline or inside your network
Teaches what resists description
mấtyou lose
Kiến thức đóng băng ở thời điểm huấn luyện
Dữ liệu lệch ⇒ model lệch, khó gỡ
Quên tai hại, kể cả khả năng từ chối
Vòng lặp sửa lỗi tính bằng giờ
Knowledge freezes at training time
Skewed data, skewed weights, hard to undo
Catastrophic forgetting, including refusals
A fix cycle measured in hours
đánh đổitrade-off
Chọn fine-tune là đổi sự linh hoạt và một vòng lặp sửa lỗi tính bằng giây lấy hành vi ổn định và chi phí mỗi request thấp ở quy mô lớn.Choosing fine-tuning trades flexibility and a fix cycle measured in seconds for stable behavior and a low per-request cost at scale.
Dấu hiệu nhận biết: bạn đang viết system prompt dài hơn 800 từ chỉ để mô tả cách trả lời, và nó vẫn bị phá vỡ ở các ca lạ.How to recognize it: you are writing an 800-word system prompt purely to describe how to answer, and it still breaks on odd cases.
04
Full vs LoRA / QLoRA
nhánh của fine-tunefine-tune branch●●○
Đã quyết fine-tune thì còn câu hỏi: cập nhật cái gì. Full đổi mọi trọng số; LoRA đóng băng gốc và chỉ huấn luyện vài ma trận nhỏ gắn thêm.Once you tune, one question remains: what gets updated. Full moves every weight; LoRA freezes the base and trains small matrices bolted alongside.
FULL ██████████████████████ toàn bộ trọng số đều đổi
→ checkpoint nặng bằng cả model, mỗi tác vụ một bản
LoRA ██████████████████████ gốc: ĐÓNG BĂNG
▒▒▒ adapter: 0,1–2% tham số
→ adapter vài chục MB, nhiều adapter chung một gốc
lớp chạy: Wx + BAx W không đổi · chỉ A, B được huấn luyện
FULL ██████████████████████ every weight moves
→ checkpoint as heavy as the model, one per task
LoRA ██████████████████████ base: FROZEN
▒▒▒ adapter: 0.1–2% of parameters
→ adapters of tens of MB, many sharing one base
layer: Wx + BAx W never changes · only A, B are trained
dùng chouse for
Mỗi khách một adapter, chung một model gốc
Đội nhỏ, ngân sách GPU hữu hạn
Cần rollback bằng cách tráo adapter
Full: chỉ khi đổi cả domain hoặc ngôn ngữ
One adapter per customer, one shared base
Small teams on a finite GPU budget
Rollback by swapping an adapter
Full: only for a domain or language shift
đượcyou gain
VRAM giảm nhiều lần — chỗ tiết kiệm thật là optimizer state
Adapter vài chục MB, version hoá gần như miễn phí
Model gốc còn nguyên, ít hư hại khả năng chung
QLoRA: tinh chỉnh 13B trên một GPU 24GB
VRAM drops several-fold — the saving is optimizer state
Adapters of tens of MB, versioning is free
Base stays intact, less collateral damage
QLoRA: tune a 13B model on one 24GB GPU
mấtyou lose
Đuối khi cần kỹ năng thực sự mới
rank thấp âm thầm giới hạn trần chất lượng
Phục vụ ở 4-bit làm chậm suy luận
Gộp adapter để deploy ⇒ mất khả năng tráo nhanh
Struggles when genuinely new skills are needed
Too low a rank silently caps quality
Serving at 4-bit slows inference
Merging for deploy costs fast swapping
đánh đổitrade-off
Chọn LoRA là đổi trần chất lượng lý thuyết trên những thay đổi sâu lấy chi phí huấn luyện thấp hơn một bậc và khả năng rollback tính bằng giây.Choosing LoRA trades a theoretical quality ceiling on deep changes for an order-of-magnitude cheaper training run and rollback in seconds.
Dấu hiệu nhận biết: nếu bạn đang phân vân, câu trả lời là LoRA. Full fine-tune là ngoại lệ cần được biện minh, không phải mặc định.How to recognize it: if you are unsure, the answer is LoRA. Full fine-tuning is an exception that needs justifying, not a default.
05
Đường ống từ đầu đến cuốiEnd-to-end pipeline
vận hànhoperations●●●
Bốn giai đoạn nối tiếp, một cổng chặn ở giữa, và một vòng lặp quay ngược về dữ liệu — không phải về siêu tham số.Four stages in sequence, one gate in the middle, and a loop back to the data — not to the hyperparameters.
hội thoại · hành vi · an toàn ← ba nguồn ví dụ
└────────┬────────┘
▼
[1] DỮ LIỆU dọn ─▶ template ─▶ tokenize ─▶ chia tập
train / val / test
▼
[2] HUẤN LUYỆN forward ─▶ loss ─▶ backprop ─▶ optimizer step
▲ │
└───────────── lặp theo epoch ─┘
▼
[3] ĐÁNH GIÁ chất lượng · an toàn · đăng ký bản
▼
╱ QUA CỔNG? ╲
KHÔNG CÓ
│ ▼
│ [4] DEPLOY version ─▶ canary ─▶ giám sát ─▶ rollback
│
└─▶ quay về [1] SỬA DỮ LIỆU
conversations · behavior · safety ← three example sources
└────────┬────────┘
▼
[1] DATA clean ─▶ template ─▶ tokenize ─▶ split
train / val / test
▼
[2] TRAINING forward ─▶ loss ─▶ backprop ─▶ optimizer step
▲ │
└───────────── loop per epoch ─┘
▼
[3] EVALUATE quality · safety · registry
▼
╱ PASSES GATES? ╲
NO YES
│ ▼
│ [4] DEPLOY version ─▶ canary ─▶ monitor ─▶ rollback
│
└─▶ back to [1] FIX THE DATA
dùng chouse for
Mọi model tinh chỉnh sắp phục vụ người dùng thật
Môi trường tuân thủ, cần truy vết dữ liệu
Nhiều người cùng đẩy dữ liệu vào một pipeline
Sản phẩm huấn luyện lại định kỳ
Any tuned model about to serve real users
Regulated settings needing data provenance
Several people feeding one pipeline
Products that retrain on a schedule
đượcyou gain
Cổng chặn hồi quy an toàn trước người dùng
Registry khiến mọi kết quả tái lập được
Canary giới hạn thiệt hại ở vài % traffic
Template chuẩn hoá diệt cả họ lỗi âm thầm
The gate stops safety regressions early
A registry makes results reproducible
Canaries cap the blast radius at a few percent
Standard templating kills a family of silent bugs
mấtyou lose
Tốn công hơn bản fine-tune đầu rất nhiều
Cổng chỉ tốt bằng bộ test đằng sau nó
Đánh giá tự động bỏ sót lỗi sắc thái
Canary cần đủ lưu lượng mới có ý nghĩa
Far more work than the first fine-tune
A gate is only as good as its test set
Automated eval misses tone failures
Canaries need traffic to mean anything
đánh đổitrade-off
Chọn pipeline đầy đủ là đổi tốc độ của lần thử đầu tiên lấy khả năng huấn luyện lại lần thứ hai mươi mà không phá vỡ thứ gì.Choosing the full pipeline trades the speed of the first attempt for the ability to retrain a twentieth time without breaking anything.
Dấu hiệu nhận biết: nếu không trả lời được "bản đang chạy huấn luyện trên tập dữ liệu nào" trong một phút, bạn chưa có pipeline — bạn có một notebook.How to recognize it: if you cannot say which dataset produced the model in production within a minute, you do not have a pipeline — you have a notebook.
Bảng đánh đổiTrade-off table
Không cột nào thắng mọi hàng. Các cột bù trừ cho nhau — đó là lý do cấu hình phổ biến nhất là fine-tune cho hành vi cộng RAG cho sự thật.No column wins every row. The columns cover for each other — which is why the common setup is fine-tuning for behavior plus RAG for facts.
trụcaxis
không dùng gìbaseline
long context
RAG
fine-tune (LoRA)
Chi phí trả trướcUpfront cost
khôngnone
khôngnone
trung bìnhmedium
caohigh
Chi phí mỗi requestPer-request cost
thấplow
cao, tăng theo tài liệuhigh, scales with document
trung bình, gần như phẳngmedium, nearly flat
thấp nhấtlowest
Thời gian đến bản chạy đượcTime to working version
giờhours
giờhours
1–3 tuầnweeks
2–6 tuầnweeks
Độ tươi của sự thậtFact freshness
tức thìinstant
tức thìinstant
vài phútminutes
chỉ khi huấn luyện lạionly on retrain
Dạy được hành viTeaches behavior
yếuweak
trung bìnhmedium
yếuweak
mạnhstrong
Trích nguồn kiểm chứng đượcVerifiable citations
khôngno
khôngno
cóyes
khôngno
Độ trễLatency
thấplow
caohigh
trung bìnhmedium
thấp nhấtlowest
Gánh nặng vận hànhOperational burden
khôngnone
khôngnone
caohigh
caohigh
Chịu được kho lớnHandles a large corpus
khôngno
khôngno
cóyes
không liên quannot applicable
Vòng lặp sửa lỗiFix cycle
giâyseconds
giâyseconds
phútminutes
giờhours
Sai lầm thường gặpAnti-patterns
sai lầmmistake
vì sao saiwhy it is wrong
sửa thế nàothe fix
Fine-tune để model "biết" tài liệu công tyFine-tuning so the model "knows" company docs
Huấn luyện dịch chuyển phong cách, không cài đặt sự kiện. Model học cách nói giống tài liệu rồi bịa số liệu.Training shifts style, it does not install facts. The model sounds like your docs, then invents numbers.
Đưa sự thật vào RAG. Fine-tune chỉ để dạy cách trình bày.Put facts in RAG. Fine-tune only for presentation.
Nhảy thẳng vào RAG khi chưa thử prompt tử tếJumping to RAG before a serious prompt
Bạn nhận một vector DB, một pipeline nạp liệu và một loại lỗi mới, để giải bài toán mà 20 dòng prompt đã xử lý xong.You inherit a vector DB, an ingestion pipeline and a new failure mode, to solve what 20 lines of prompt already solved.
Đi hết baseline trước. Ghi lại lý do nó không đủ.Work through the baseline. Write down why it fell short.
Fine-tune với 100 ví dụ tự sinhFine-tuning on 100 synthetic examples
Quá ít để tổng quát hoá, đủ nhiều để cài lệch vào trọng số.Too few to generalize, plenty to bake a bias into the weights.
Tối thiểu 500 ví dụ đã kiểm tay. Chưa đủ thì ở lại few-shot.500 hand-reviewed examples minimum, otherwise stay on few-shot.
Chỉ dùng tìm kiếm vector, bỏ từ khoáVector search only, no keywords
Ngữ nghĩa không phân biệt được ERR-4021 với ERR-4012.Semantics cannot tell ERR-4021 from ERR-4012.
Hybrid BM25 cộng vector, thêm rerank.Hybrid BM25 plus vectors, then rerank.
Không có tập test đóng băngNo frozen test set
Mọi cải thiện đều là ảo giác vì bạn đang tinh chỉnh theo chính thước đo.Every improvement is an illusion, because you are tuning against your own ruler.
Tách test từ ngày đầu, khoá lại, chỉ dùng ở cổng.Split it out on day one, lock it, use it only at the gate.
Template lúc huấn luyện khác lúc chạyTraining template differs from serving
Eval đẹp, production tệ, và không ai hiểu vì sao.Evaluation looks great, production is bad, nobody knows why.
Một hàm dựng prompt duy nhất, dùng chung cho cả hai đường.One prompt-building function, shared by both paths.
Chỉnh siêu tham số khi không qua cổngTuning hyperparameters when the gate fails
Vấn đề gần như luôn nằm ở dữ liệu; chỉnh tham số chỉ che triệu chứng.The problem is almost always the data; tweaks only mask the symptom.
Đọc lại 100 ví dụ trước khi động vào learning_rate.Reread 100 examples before touching learning_rate.
Nhồi hết cửa sổ vì "model hỗ trợ 1 triệu token"Filling the window because "it supports a million tokens"
Chú ý loãng ở giữa, chi phí và độ trễ tăng tuyến tính.Attention thins in the middle, cost and latency grow linearly.
Giữ dưới 60% cửa sổ. Vượt thì chuyển sang truy hồi.Stay under 60% of the window, then move to retrieval.
Deploy model mới cho 100% trafficShipping a new model to 100% of traffic
Hồi quy an toàn lộ ra khi tất cả người dùng đã gặp nó.Safety regressions surface after every user has met them.
Canary vài phần trăm, giám sát, giữ nút rollback.Canary a few percent, monitor, keep rollback ready.
Chunk 500 token không có tiêu đề500-token chunks with no headings
Gắn tiêu đề tài liệu và tiêu đề mục vào đầu mỗi chunk.Prepend document title and section heading to each chunk.
Ba câu cần nhớThree sentences to remember
Fine-tune dạy model nói thế nào; truy hồi quyết định model nói về cái gì. Dùng nhầm chiều là nguồn gốc của phần lớn dự án thất bại.Fine-tuning teaches the model how to speak; retrieval decides what it speaks about. Getting that direction backwards is the root of most failed projects.
Trước khi chọn bất cứ cái nào trong ba, hãy chứng minh rằng một system prompt tốt cộng vài ví dụ few-shot là không đủ. Phần lớn trường hợp bạn sẽ không chứng minh nổi.Before choosing any of the three, prove that a good system prompt plus a few few-shot examples is not enough. Most of the time you will fail to prove it.
Khi model tinh chỉnh không qua cổng kiểm, mặc định là quay về sửa dữ liệu, không phải chỉnh siêu tham số.When a tuned model fails the gate, the default move is to fix the data, not the hyperparameters.