01API
Gọi modelModel calls
[app] ─(system + messages)─► [model] ─(text + usage)─► [app]
Một lời gọi HTTP gửi tin nhắn, nhận văn bản và số token. Mọi thứ khác chỉ là chuẩn bị đầu vào và xử lý đầu ra cho lời gọi này.
One HTTP call: send messages, get text and token counts back. Everything else prepares input and handles output for this call.
Chọn gọi model qua API là đổi quyền kiểm soát hạ tầng và phí theo token lấy năng lực model hàng đầu ngay hôm nay mà không phải vận hành gì.
Calling a model via API trades infrastructure control and a per-token fee for top-tier capability today with nothing to operate.
- Dùng cho
- Đo chi phí, độ trễ thật; so hai model trên cùng 20 câu hỏi.
- Được
- Model mạnh sau vài dòng code, trả theo lượng dùng, đổi model bằng một tham số.
- Mất
- Dữ liệu rời hạ tầng của bạn; rate limit và lỗi tạm thời; hành vi đổi nếu gọi alias kiểu “latest”. Ghim đúng model ID (vd.
claude-haiku-5-5, không có hậu tố ngày) trong config, chỉ đổi sau khi chạy lại Eval.
- Xong khi
- Script in ra câu trả lời và số token.
- Use for
- Measuring real cost and latency; comparing two models on the same 20 questions.
- Gain
- A strong model in a few lines, pay per use, switch models with one parameter.
- Lose
- Data leaves your infrastructure; rate limits and transient errors; behavior shifts behind a “latest”-style alias. Pin the exact model ID (e.g.
claude-haiku-5-5, no date suffix) in config and change it only after re-running Eval.
- Done when
- A script prints the answer and token counts.
Dấu hiệu: bạn chưa biết một câu trả lời tốn bao nhiêu tiền và mất bao lâu.
Signal: you don't yet know what one answer costs or how long it takes.
02Prompt
Gọi modelModel calls
system: vai trò · quy tắc · định dạng
user: <documents>…</documents> + câu hỏi
Chỉ dẫn và ngữ cảnh gửi kèm câu hỏi. Đây là mã nguồn hành vi của app, viết bằng ngôn ngữ tự nhiên.
The instructions and context sent with the question. It's the app's behavior, written as natural-language source code.
Chọn điều khiển hành vi bằng prompt là đổi sự chắc chắn của code lấy tốc độ lặp tính bằng phút.
Controlling behavior through prompts trades the certainty of code for iteration measured in minutes.
- Dùng cho
- Ép trả lời ngắn, có nguồn, từ chối bằng một câu cố định khi thiếu thông tin.
- Được
- Sửa trong vài phút, không cần hạ tầng; prompt dài gần như miễn phí khi có caching.
- Mất
- Chỉ đề nghị, không bảo đảm; sửa lỗi A dễ sinh lỗi B; không thêm được kiến thức.
- Xong khi
- Với 5 đoạn dán tay, bot trả lời đúng định dạng và từ chối được câu ngoài tài liệu.
- Use for
- Forcing short, cited answers and a fixed refusal string when info is missing.
- Gain
- Fixes in minutes, no infrastructure; long prompts nearly free with caching.
- Lose
- Suggests, doesn't guarantee; fixing A breeds B; can't add knowledge.
- Done when
- Given 5 pasted passages, the bot answers in format and refuses off-doc questions.
Dấu hiệu: model có đủ thông tin nhưng trả lời sai cách.
Signal: the model has the information but answers the wrong way.
nạp: tài liệu ► chunk ► embedding ► kho (+ quyền xem)
hỏi: câu hỏi ► embedding ► top-k ► rerank ► prompt
Tìm vài đoạn tài liệu liên quan nhất rồi đặt vào prompt. Model trả lời từ đoạn được đưa vào, không từ trí nhớ. Chunk khởi đầu 512–1024 token, chồng lấn 10–15%, giống RAG 101.
Find the few most relevant passages and put them in the prompt. The model answers from them, not from memory. Start chunks at 512–1024 tokens with 10–15% overlap, as in RAG 101.
Chọn RAG là đổi một pipeline dữ liệu phải bảo trì lấy câu trả lời bám tài liệu mới nhất mà không nhồi cả kho vào mỗi request.
Choosing RAG trades a data pipeline to maintain for answers grounded in the latest docs without stuffing the whole collection into every request.
- Dùng cho
- Kho quá lớn cho context, tài liệu đổi thường xuyên, cần phân quyền theo người.
- Được
- Giảm bịa mạnh, cập nhật bằng cách nạp lại (re-index), chi phí gần như không theo kích thước kho.
- Mất
- Tìm sai đoạn là trả lời sai tự tin; yếu với mã số và tên riêng; thêm pipeline phải bảo trì.
- Xong khi
- Đoạn đúng nằm trong top-5 ở phần lớn câu của bộ Eval.
- Use for
- Collections too large for context, docs that change often, per-user permissions.
- Gain
- Far less fabrication, update by re-indexing, cost nearly flat with collection size.
- Lose
- Wrong passage, confidently wrong answer; weak on codes and names; another pipeline to run.
- Done when
- The right passage is in the top 5 for most Eval questions.
Dấu hiệu: model sai vì thiếu thông tin, không phải vì hiểu sai chỉ dẫn.
Signal: the model is wrong because it lacks information, not because it misread instructions.
bộ câu hỏi ► app ► chấm truy xuất (recall@k)
└► chấm trả lời (đúng · có nguồn · bám tài liệu)
Bộ câu hỏi cố định có đáp án, cùng script chấm tự động. Đây là unit test của app AI.
A fixed question set with expected answers plus an automatic grader. The unit tests of an AI app.
Chọn đầu tư vào Eval là đổi vài ngày viết bộ test lúc đầu lấy khả năng biết chắc mỗi thay đổi làm app tốt lên hay tệ đi.
Investing in Eval trades a few days of test-writing upfront for knowing whether each change makes the app better or worse.
- Dùng cho
- Quyết định đổi prompt, chunk hay model; bắt hồi quy (regression); khoanh lỗi ở truy xuất hay ở sinh.
- Được
- Cảm giác thành con số; kiểm chứng trong vài phút; bộ test lớn dần từ log thật.
- Mất
- Tốn công lúc đầu; chỉ đo được thứ nó chứa; LLM-as-judge có thiên lệch riêng.
- Xong khi
- Một lệnh in ra recall@5, tỷ lệ đúng, tỷ lệ từ chối đúng cho hai phiên bản.
- Use for
- Deciding on prompt, chunking, or model changes; catching regressions; locating errors.
- Gain
- Gut feeling becomes numbers; verify in minutes; the set grows from real logs.
- Lose
- Upfront effort; measures only what it contains; LLM judges have biases.
- Done when
- One command prints recall@5, accuracy, and correct-refusal rate for two versions.
Dấu hiệu: bạn đánh giá app bằng cách thử vài câu rồi nói "có vẻ ổn".
Signal: you judge the app by trying a few questions and saying "looks fine".
05Guardrail
Kiểm soátControl
vào: phạm vi · dữ liệu cá nhân · chèn lệnh
truy: chỉ tài liệu người hỏi được xem
ra: có nguồn? nguồn có thật? ► gửi / câu dự phòng
Các lớp kiểm tra bằng code bao quanh lời gọi model. Prompt xin model làm đúng, guardrail kiểm tra xem model có làm đúng không.
Layers of code checks around the model call. The prompt asks the model to behave; the guardrail checks that it did.
Chọn thêm guardrail là đổi một ít độ trễ và một tỷ lệ từ chối nhầm lấy giới hạn trên cho thiệt hại khi model sai.
Adding guardrails trades a little latency and some false refusals for an upper bound on damage when the model is wrong.
- Dùng cho
- Chặn trả lời không nguồn hoặc nguồn bịa, chặn lộ tài liệu ngoài quyền, chặn prompt injection.
- Được
- Trần thiệt hại cố định; kiểm tra bằng code gần như miễn phí; mỗi lần chặn là dữ liệu cho Eval.
- Mất
- Giảm chứ không xoá rủi ro; chặt quá thì từ chối nhầm; model phụ làm tăng độ trễ.
- Xong khi
- Mọi câu tấn công trong bộ test bị chặn mà tỷ lệ đúng không giảm đáng kể.
- Use for
- Blocking uncited or fake-cited answers, permission leaks, and prompt injection.
- Gain
- A fixed damage ceiling; code checks nearly free; every block is Eval data.
- Lose
- Reduces risk, doesn't remove it; too strict means false refusals; helper models add latency.
- Done when
- Every attack question in the test set is blocked without a real drop in accuracy.
Dấu hiệu: có một loại lỗi mà xảy ra dù một lần cũng không chấp nhận được.
Signal: there's a class of error that is unacceptable even once.
06Triển khaiDeploy
Vận hànhOperations
người dùng ► web / Slack ► backend ► [05 → 03 → 02 → 01 → 05]
└► log · 👍/👎 · nạp lại tài liệu
Bọc pipeline thành dịch vụ có giao diện, log, trần chi phí và cách cập nhật tài liệu. Bản demo thành sản phẩm ở bước này.
Wrap the pipeline in a service with a UI, logs, a cost cap, and doc updates. This is where the demo becomes a product.
Chọn đưa lên production là đổi sự yên tĩnh của bản demo lấy dữ liệu thật về cách người dùng hỏi, thứ duy nhất cho biết app có giá trị.
Going to production trades the quiet of a demo for real data on how users ask, the only proof the app has value.
- Dùng cho
- Thu câu hỏi thật, đo số câu không còn đến tay phòng Nhân sự, phát hiện tài liệu lỗi thời.
- Được
- Streaming: chữ hiện sau chưa tới một giây, guardrail đầu ra chạy trên toàn văn rồi thay câu dự phòng nếu sai; log thật nuôi Eval; 👍/👎 gần như miễn phí; phát hành dần giới hạn sự cố.
- Mất
- Log là dữ liệu nhạy cảm; quên nạp lại là trả lời theo quy định cũ; chi phí có thể tăng vọt.
- Xong khi
- 10 người dùng thật dùng một tuần, có log, có chi phí thật, lỗi đã vào bộ Eval.
- Use for
- Collecting real questions, measuring how many no longer reach HR, spotting stale docs.
- Gain
- Streaming shows text in under a second, then the output guardrail checks the full text and swaps in the fallback if needed; real logs feed Eval; 👍/👎 is nearly free; gradual rollout limits incidents.
- Lose
- Logs are sensitive; a missed re-index means outdated answers; costs can spike.
- Done when
- 10 real users for a week, with logs, real cost, and failures added to Eval.
Dấu hiệu: Eval đã đạt mục tiêu và bạn bắt đầu tự nghĩ câu hỏi để thử.
Signal: Eval hit its targets and you've started inventing questions to try.