12 khái niệm RAG12 RAG concepts

Retrieval-Augmented GenerationRetrieval-Augmented Generation

12 khái niệm RAG12 RAG Concepts

RAG không phải phép màu — nó là 12 bộ phận chuyển động.RAG isn't magic — it's 12 moving parts.

Retrieval-Augmented Generation, đọc theo hướng ra quyết địnhRetrieval-Augmented Generation, read as a set of decisions

LÚC INDEXINDEX TIMELÚC TRUY VẤNQUERY TIMEKHOSTORETài liệu nguồnSource docs04Cắt chunkChunking01EmbeddingEmbeddingsCâu hỏiQuestion03·06Tìm kiếmSearch07Lọc phạm viScope filter02Vector DBVector DB12Đồ thị tri thứcKnowledge graph05Xếp lại hạngRe-ranking08Cửa sổ ngữ cảnhContext window10Neo nguồnGrounding09Chặn ảo giácGuardCâu trả lờiAnswer11Lúc index — chạy một lần hoặc định kỳIndex time — once or on a scheduleLúc truy vấn — chạy mỗi câu hỏiQuery time — every single question11 · Nguồn đổi thì index phải đổi theo11 · Sources change, the index must follow

Chọn cái nàoWhich one to use

Trước khi chọn bất kỳ khái niệm nào ở dưới, hãy kiểm tra xem bạn có cần khái niệm nào không. Đây thường là phần hữu ích nhất và cũng là phần bị bỏ qua nhiều nhất.Before picking any concept below, check whether you need any of them at all. This is usually the most useful section and the one most often skipped.

Bỏ qua toàn bộ RAG khiSkip RAG entirely when

  • Corpus dưới khoảng 50 trang (≈ 25–35k token) và ít thay đổi → dán thẳng toàn bộ vào context window. Rẻ hơn, chính xác hơn, không có gì để vận hành. Prompt caching làm chi phí lặp lại giảm mạnh.The corpus is under roughly 50 pages (≈ 25–35k tokens) and rarely changes → paste all of it into the context window. Cheaper, more accurate, nothing to operate. Prompt caching makes repeat calls far less expensive.
  • Câu trả lời nằm trong một trường của cơ sở dữ liệu → viết SQL hoặc gọi API. “Doanh thu quý ba là bao nhiêu” không phải bài toán tìm kiếm ngữ nghĩa.The answer lives in a database column → write SQL or call an API. “What was Q3 revenue” is not a semantic search problem.
  • Tri thức tĩnh và phổ thông → model đã biết rồi; RAG chỉ thêm nhiễu.The knowledge is static and general → the model already has it; RAG only adds noise.
  • Người dùng biết chính xác tên tài liệu → tìm kiếm từ khoá và trả về link. Không cần LLM.The user knows the exact document name → keyword search and return the link. No LLM needed.
  • Câu trả lời phải chính xác tuyệt đối và liệt kê được hữu hạn → bảng FAQ tra cứu, LLM chỉ là phương án dự phòng.The answer must be exactly right and the set is finite → a lookup table of FAQs, with the LLM only as fallback.

Thang leoThe ladder

  1. Prompt tĩnh với tài liệu dán cứng.A static prompt with the documents hard-coded.
  2. Prompt caching cộng toàn bộ corpus.Prompt caching plus the whole corpus.
  3. Một retriever đơn giản rồi dán top-5 — BM25 nếu người dùng gõ đúng mã hoặc ID, embedding cộng vector database nếu họ hỏi bằng lời của mình. Đây đã là RAG, và thường là đủ.One simple retriever, then paste the top 5 — BM25 if users type exact codes or IDs, embeddings plus a vector database if they ask in their own words. This is already RAG, and it is often enough.
  4. Dựng một golden set (bộ câu hỏi đánh giá chuẩn) nhỏ và đo; sau đó chuyển sang hybrid (BM25 + vector, trộn bằng RRF).Build a small golden set and measure; then go hybrid (BM25 + vectors fused with RRF).
  5. Thêm rerank (xếp hạng lại), rồi guard, và cuối cùng mới tới knowledge graph.Add reranking, then guards, and only at the very end a knowledge graph.

Quy tắc: chỉ leo lên bậc tiếp theo khi đo được rằng bậc hiện tại đang hỏng.The rule: climb to the next rung only when you can measure the current one failing.

Câu hỏi trả lời được bằng một truy vấn CSDL hoặc API?
├─ Có  → viết SQL / gọi API. Dừng.
└─ Không
   │
   Toàn bộ tài liệu dưới ~50 trang (~30k token) và ít đổi?
   ├─ Có  → dán hết vào context + prompt caching. Dừng.            (08)
   └─ Không
      │
      Người dùng có gõ đúng mã, số hiệu, tên riêng không?
      ├─ Thường xuyên   → BM25 trước, thêm vector sau              (06)
      └─ Diễn đạt tự do → embedding + vector database              (01 02 03)
         │
         Đo recall@50 và recall@5 trên tập vàng:
         ├─ recall@50 thấp           → sửa CHUNKING trước          (04)
         │                             rồi mới thêm HYBRID         (06)
         ├─ recall@50 cao, @5 thấp   → thêm RE-RANKING             (05)
         └─ cả hai đều cao           → vấn đề nằm ở khâu sinh
            │
            ├─ nhiều tenant / quyền / mốc thời gian → METADATA FILTER   (07)
            ├─ model bịa dù ngữ cảnh đúng           → GROUNDING + GUARD (10 09)
            ├─ câu hỏi phải nối nhiều thực thể      → KNOWLEDGE GRAPH   (12)
            └─ đúng hôm nay, sai sau ba tháng       → DATA DRIFT        (11)Can one database query or API call answer it?
├─ Yes → write the SQL / call the API. Stop.
└─ No
   │
   Is the whole corpus under ~50 pages (~30k tokens) and stable?
   ├─ Yes → paste it all into context + prompt caching. Stop.      (08)
   └─ No
      │
      Do users type exact codes, IDs or proper nouns?
      ├─ Often      → BM25 first, add vectors later                (06)
      └─ Free-form  → embeddings + vector database                 (01 02 03)
         │
         Measure recall@50 and recall@5 on a golden set:
         ├─ recall@50 low            → fix CHUNKING first          (04)
         │                             then add HYBRID             (06)
         ├─ recall@50 high, @5 low   → add RE-RANKING              (05)
         └─ both high                → the problem is generation
            │
            ├─ many tenants / roles / date scopes → METADATA FILTER     (07)
            ├─ invents facts despite good context → GROUNDING + GUARD   (10 09)
            ├─ questions must join entities       → KNOWLEDGE GRAPH     (12)
            └─ right today, wrong in three months → DATA DRIFT          (11)

Mười hai khái niệmThe twelve concepts

Số 01–12 là mã định danh lấy từ ảnh gốc, không phải thứ tự thực hiện. Chỉ khối “nạp” và khối “truy xuất” (retrieval) có thứ tự thật bên trong; 08 và 11 là ràng buộc chứ không phải bước.The numbers 01–12 are identifiers taken from the original image, not an execution order. Only the ingest block and the retrieval block have a real internal sequence; 08 and 11 are constraints rather than steps.

01

Vector EmbeddingsVector Embeddings

Nạp & Biểu diễnIngest & Representation

Biến text thành số mang nghĩa.Turns text into meaning-rich numbers.

Hàm biến một đoạn text thành vector d chiều cố định (768–3072), sao cho khoảng cách hình học phản ánh khoảng cách ngữ nghĩa. Không phải nén, không phải hash: hai câu không trùng một chữ nào vẫn có thể nằm sát nhau.A function that turns a piece of text into a fixed d-dimensional vector (768–3072) such that geometric distance mirrors semantic distance. Not compression, not hashing: two sentences sharing zero words can still sit right next to each other.

"con mèo đang ngủ"  ──┐
                      ├─►[ encoder ]──► [0.12, -0.44, ..., 0.03]   d=1536
"con miu ngủ gật"  ───┘                        │
                                        cos(a,b) = 0.86  → gần nghĩa
"lãi suất ngân hàng" ─►[ encoder ]──► [...]    cos = 0.07  → khác nghĩa

Đánh đổiTrade-offChọn embedding là đổi khả năng khớp chính xác từng ký tự lấy khả năng khớp ý nghĩa.Choosing embeddings trades exact character-level matching for meaning-level matching.

Dùng choUse it for

  • Tìm ticket hỗ trợ trùng lặp khi mỗi người mô tả cùng một lỗi bằng lời khác nhau.Finding duplicate support tickets when every reporter words the same bug differently.
  • Gợi ý điều khoản hợp đồng tương tự trong kho 200k điều khoản.Suggesting similar contract clauses across a 200k-clause repository.
  • Phân cụm 50k phản hồi khách hàng thành chủ đề mà không cần định nghĩa trước.Clustering 50k customer comments into themes without predefining the themes.
  • Định tuyến câu hỏi tới đúng phòng ban dựa trên ý định, không dựa từ khoá.Routing a question to the right team by intent rather than by keyword.

ĐượcYou gain

  • Bắt được nhiều cách diễn đạt cùng một ý — thứ BM25 hoàn toàn mù.Catches many phrasings of one idea — exactly what BM25 is blind to.
  • Một vector 1536 chiều ≈ 6KB; so sánh hàng triệu vector chỉ là một phép nhân ma trận.One 1536-dim vector ≈ 6KB; comparing millions of them is one matrix multiply.
  • Model đa ngữ cho phép hỏi tiếng Việt, tìm thấy tài liệu tiếng Anh.A multilingual model lets you ask in Vietnamese and hit English documents.
  • Chi phí embed rẻ (~$0.02–0.13 / 1M token) và chỉ trả một lần cho mỗi chunk.Embedding is cheap (~$0.02–0.13 per 1M tokens) and paid once per chunk.

MấtYou lose

  • Mù với từ hiếm: mã SKU “AX-9920”, tên riêng, số hiệu văn bản thường bị nhoè.Blind to rare tokens: SKUs like “AX-9920”, proper nouns and document numbers get smeared.
  • Không hiểu phủ định: “có điều khoản phạt” và “không có điều khoản phạt” nằm rất gần nhau.No grasp of negation: “has a penalty clause” and “has no penalty clause” sit very close together.
  • Đổi model embedding = re-embed toàn bộ corpus; hai không gian vector không trộn được.Changing the embedding model means re-embedding everything; two vector spaces never mix.
  • Điểm cosine không hiệu chuẩn: 0,82 không có nghĩa “chắc 82%”, và ngưỡng không chuyển được giữa các model.Cosine scores are uncalibrated: 0.82 does not mean “82% sure”, and thresholds do not transfer between models.
  • Vector kế thừa ranh giới miền của dữ liệu huấn luyện; văn bản chuyên ngành hẹp thường bị bẹp lại.Vectors inherit the domain boundaries of their training data; narrow specialist text tends to collapse together.

Dấu hiệu nhận biếtHow to tellNgười dùng hỏi bằng lời của họ, không bằng từ có trong tài liệu.Users ask in their own words, not in the words the documents use.

02

Vector DatabaseVector Database

Nạp & Biểu diễnIngest & Representation

Index vector để tìm nhanh.Indexes vectors for fast search.

Kho lưu vector kèm index ANN, cho phép tìm k láng giềng gần nhất trong hàng trăm triệu vector ở mức mili-giây, cộng với lọc theo payload, cập nhật và bảo đảm bền vững. Điểm mấu chốt: nó trả về kết quả gần đúng, không phải chính xác.A store for vectors plus an ANN index that finds the k nearest neighbours among hundreds of millions of vectors in milliseconds, together with payload filtering, updates and durability. The key point: it returns approximate results, not exact ones.

upsert:  chunk ──►embed──► [vec | payload{doc_id, tenant, date, acl}]
                                    │
                               ┌────▼────┐
query:   q ──►embed──►         │  HNSW   │  duyệt đồ thị nhiều tầng
                               │  IVF    │  ~log(N) thay vì N
                               └────┬────┘
                            top-k + score + payload

Đánh đổiTrade-offChọn vector database là đổi độ chính xác tuyệt đối và sự đơn giản hạ tầng lấy độ trễ ổn định ở quy mô lớn.Choosing a vector database trades exact results and infrastructure simplicity for predictable latency at scale.

Dùng choUse it for

  • Kho tài liệu nội bộ 10 triệu chunk cần trả kết quả dưới 100 ms.An internal corpus of 10M chunks that must answer in under 100 ms.
  • Nhiều khách hàng dùng chung một index, cách ly bằng payload tenant.Many customers sharing one index, isolated by a tenant field in the payload.
  • Tìm ảnh hoặc âm thanh tương tự bằng embedding đa phương thức.Similar-image or similar-audio lookup over multimodal embeddings.
  • Khử trùng lặp bản ghi ở quy mô hàng triệu dòng.Deduplicating records at a scale of millions of rows.

ĐượcYou gain

  • ANN đưa tìm kiếm từ O(N) về khoảng O(log N); 10 triệu vector vẫn dưới 50 ms.ANN takes search from O(N) to roughly O(log N); 10M vectors still answer under 50 ms.
  • Lọc và tìm trong cùng một lần gọi, không phải hai vòng ứng dụng.Filtering and searching in a single call instead of two application round trips.
  • Có sẵn sao lưu, sharding, replica — những thứ bạn không muốn tự viết.Backups, sharding and replicas come with the box — things you do not want to write.
  • pgvector cho phép giữ vector cạnh dữ liệu quan hệ: một transaction, một bản backup.pgvector keeps vectors beside relational data: one transaction, one backup.

MấtYou lose

  • ANN là gần đúng: recall thực tế 95–99%, và bạn không biết mình đã mất tài liệu nào.ANN is approximate: real recall lands at 95–99%, and you cannot see which documents you lost.
  • Index HNSW ngốn RAM: khoảng (d×4 + M×8) byte mỗi vector → 10M vector, d=1536 ≈ 70–90 GB.An HNSW index eats RAM: about (d×4 + M×8) bytes per vector → 10M vectors at d=1536 ≈ 70–90 GB.
  • Xoá và cập nhật trên HNSW tốn kém; nhiều hệ chỉ đánh dấu tombstone tới khi rebuild.Deletes and updates on HNSW are expensive; many engines only tombstone until the next rebuild.
  • Thêm một hệ thống có trạng thái vào kiến trúc: một nơi nữa để backup, giám sát và mất dữ liệu.It adds a stateful system to your architecture: one more thing to back up, monitor and lose.
  • Với corpus tới khoảng 100k vector, chi phí quản trị lớn hơn lợi ích — numpy hoặc FAISS flat (tìm chính xác) là đủ.Up to roughly 100k vectors the operational cost outweighs the benefit — numpy or a flat (exact) FAISS index is enough.

Dấu hiệu nhận biếtHow to tellQuét toàn bộ mất hơn 100 ms, hoặc corpus vượt khoảng 100k vector; qua ~1M thì chắc chắn cần.A brute-force scan takes over 100 ms, or the corpus passes roughly 100k vectors; past ~1M you definitely do.

03

Semantic SearchSemantic Search

Truy xuấtRetrieval

Tìm theo nghĩa, không theo từ khoá.Finds by meaning, not keywords.

Bài toán truy xuất trong đó điểm liên quan được tính bằng khoảng cách vector giữa câu hỏi và tài liệu, thay vì bằng độ trùng từ. Đây là ứng dụng của 01 và 02 chứ không phải một thành phần hạ tầng riêng — đừng đi mua một “hệ semantic search” khi bạn đã có hai thứ kia.The retrieval problem where relevance is scored by vector distance between question and document instead of term overlap. It is an application of 01 and 02, not a separate piece of infrastructure — do not go shopping for a “semantic search system” when you already have those two.

keyword :  "chính sách hoàn tiền"
             └─► chỉ khớp tài liệu chứa đúng chữ đó

semantic:  "mua rồi trả lại được không"
             └─► khớp "Điều 7. Hoàn trả hàng hoá"    (0 từ trùng nhau)

Đánh đổiTrade-offChọn semantic search là đổi tính giải thích được và độ chính xác trên từ hiếm lấy độ phủ trên mọi cách diễn đạt.Choosing semantic search trades explainability and rare-term precision for coverage across every phrasing.

Dùng choUse it for

  • Trợ lý hỗ trợ khách hàng: người hỏi bằng ngôn ngữ đời thường, tài liệu viết bằng ngôn ngữ pháp lý.A support assistant where people speak plainly and the documents speak legalese.
  • Tìm kiếm nội bộ khi mỗi phòng ban gọi cùng một thứ bằng một cái tên khác nhau.Internal search where each department has its own name for the same thing.
  • Tra cứu đa ngôn ngữ trên một corpus chỉ có một ngôn ngữ.Cross-language lookup over a single-language corpus.
  • Gợi ý bài liên quan mà không phải gắn tag thủ công.Related-article suggestions without hand-maintained tags.

ĐượcYou gain

  • Bắt được cách nói vòng, cách nói tắt và lỗi chính tả mà không cần từ điển đồng nghĩa.Handles roundabout phrasing, abbreviations and typos without a synonym dictionary.
  • Không phải bảo trì danh sách stopword, synonym hay tag thủ công.No stopword lists, synonym tables or hand-maintained tags to keep alive.
  • Hoạt động ngay trên corpus mới mà không cần huấn luyện gì thêm.Works on a brand new corpus with no extra training.
  • Cho phép hỏi bằng một ngôn ngữ và tìm trong ngôn ngữ khác.Lets people ask in one language and search in another.

MấtYou lose

  • Thua BM25 rõ rệt ở truy vấn chứa mã, số hiệu hoặc tên riêng.Clearly loses to BM25 on queries containing codes, reference numbers or proper nouns.
  • Không có khái niệm “chắc chắn khớp” — mọi kết quả đều là gần đúng.There is no notion of an exact match — every result is an approximation.
  • Khó giải thích vì sao một kết quả xuất hiện, nên khó gỡ lỗi cùng người dùng.Hard to explain why a result surfaced, so hard to debug alongside a user.
  • Ngưỡng điểm không ổn định giữa các truy vấn, không dùng làm bộ lọc cứng được.Score thresholds drift between queries, so they cannot act as a hard filter.
  • Kết quả “đúng chủ đề nhưng sai chủ thể” trông rất thuyết phục và rất dễ lọt.Results that are on-topic but about the wrong entity look convincing and slip through easily.

Dấu hiệu nhận biếtHow to tellNgười dùng bỏ cuộc sau hai, ba lần gõ lại từ khoá.Users give up after rephrasing their keywords two or three times.

04

ChunkingChunking

Nạp & Biểu diễnIngest & Representation

Cắt tài liệu thành mảnh đúng cỡ.Splits docs into right-sized pieces.

Cắt tài liệu thành đơn vị truy xuất. Đây là quyết định có ảnh hưởng lớn nhất tới chất lượng RAG, tốn ít tiền nhất, và bị làm ẩu nhiều nhất.Cutting documents into retrieval units. This is the single highest-impact decision in a RAG system, the cheapest one to get right, and the one most often done carelessly.

tài liệu 40 trang
│
├─ 200 token  :  ████ ████ ████ ████   recall cao, mỗi mảnh thiếu ngữ cảnh
├─ 800 token  :  ████████ ████████     cân bằng thường dùng
└─ 4000 token :  ████████████████      mỗi mảnh loãng, embed bị trung bình hoá

overlap 15% :   [.....A.....]
                        [.....B.....]   ← câu ở mép không bị mất

Đánh đổiTrade-offChọn chunk nhỏ là đổi ngữ cảnh bên trong mỗi chunk lấy độ chính xác của phép khớp.Choosing smaller chunks trades the context inside each piece for the precision of the match.

Dùng choUse it for

  • Hợp đồng: cắt theo điều và khoản, không theo số token.Contracts: split by article and clause, never by token count.
  • Wiki nội bộ: cắt theo heading, gắn đường dẫn heading vào đầu mỗi chunk.Internal wikis: split by heading and prepend the heading path to each piece.
  • Bản ghi hội thoại: cắt theo lượt nói cộng một cửa sổ trượt.Meeting transcripts: split by speaker turn plus a sliding window.
  • Bảng và CSV: mỗi hàng là một chunk, lặp lại dòng header trong từng chunk.Tables and CSVs: one row per chunk, with the header row repeated in each.
  • Mã nguồn: cắt theo hàm hoặc class bằng AST, không bao giờ theo số dòng.Source code: split by function or class using an AST, never by line count.

ĐượcYou gain

  • Chunk đúng cỡ nâng recall nhiều hơn bất kỳ mẹo nào khác, với chi phí gần bằng không.Right-sized chunks lift recall more than any other trick, at nearly zero cost.
  • Giảm số token phải nhồi vào prompt, nên giảm cả tiền lẫn nhiễu.Fewer tokens pushed into the prompt, which cuts both spend and noise.
  • Cho phép trích dẫn chính xác tới vị trí, thay vì trỏ vào cả tài liệu 40 trang.Enables precise citations to a location instead of pointing at a 40-page file.
  • Cắt theo cấu trúc là logic thuần, không cần model, không cần GPU.Structural splitting is plain logic — no model, no GPU.

MấtYou lose

  • Không có cỡ tối ưu chung; nó phụ thuộc dạng tài liệu và dạng câu hỏi.There is no universally optimal size; it depends on the document type and the question type.
  • Cắt sai làm đứt bảng, danh sách đánh số và câu điều kiện, khiến chunk mất nghĩa.Bad cuts sever tables, numbered lists and conditional sentences, leaving meaningless fragments.
  • Overlap làm phình index thêm 15–30% cả về dung lượng lẫn chi phí embed.Overlap inflates the index by 15–30% in both storage and embedding cost.
  • Đổi chiến lược chunk đồng nghĩa với re-index toàn bộ corpus.Changing the chunking strategy means re-indexing the entire corpus.
  • Chunk nhỏ mất chủ ngữ (“nó”, “bên A”) và trở nên vô nghĩa khi tách khỏi ngữ cảnh.Small chunks lose their subject (“it”, “the party”) and become meaningless out of context.

Dấu hiệu nhận biếtHow to tellHệ thống trả về đúng tài liệu nhưng sai đoạn, hoặc đoạn cụt đầu cụt đuôi.The system returns the right document but the wrong passage, or a passage cut off at both ends.

05

Re-rankingRe-ranking

Truy xuấtRetrieval

Xếp lại kết quả theo độ liên quan thật.Reorders hits by true relevance.

Tầng chấm điểm thứ hai. Bi-encoder (embedding) mã hoá câu hỏi và tài liệu độc lập nên rẻ nhưng thô; cross-encoder đọc cặp (câu hỏi, tài liệu) cùng lúc nên chính xác hơn nhiều nhưng đắt gấp hàng trăm lần. Chiến lược: lấy rộng bằng bi-encoder, lọc tinh bằng cross-encoder.A second scoring stage. A bi-encoder embeds question and document separately, so it is cheap but coarse; a cross-encoder reads the (question, document) pair together, so it is far more accurate but hundreds of times more expensive. The strategy: cast wide with the bi-encoder, then filter sharply with the cross-encoder.

q ─► bi-encoder ─► top-50        rẻ, ~10 ms, hơi thô
                      │
                      ▼
        cross-encoder(q, d) cho từng d      đắt, ~50–300 ms
                      │
                      ▼
                   top-5 ─► prompt

Đánh đổiTrade-offChọn reranking là đổi độ trễ và chi phí trên mỗi truy vấn lấy độ chính xác ở những vị trí đầu tiên.Choosing re-ranking trades per-query latency and cost for precision at the very top of the list.

Dùng choUse it for

  • Trợ lý pháp lý hoặc y tế, nơi kết quả ở vị trí số một buộc phải đúng.Legal or medical assistants where the top-ranked result has to be the right one.
  • Corpus chứa nhiều tài liệu gần giống nhau, ví dụ nhiều phiên bản của một chính sách.Corpora full of near-duplicate documents, such as many versions of one policy.
  • Khi ngân sách token hẹp nên chỉ đưa được ba đến năm chunk vào prompt.Tight token budgets that only allow three to five chunks in the prompt.
  • RAG trên corpus nhiễu như email, ticket hoặc chat nội bộ.RAG over noisy corpora like email, tickets or internal chat.

ĐượcYou gain

  • Thường tăng 10–25 điểm nDCG@5 so với chỉ dùng vector search.Typically adds 10–25 nDCG@5 points over vector search alone.
  • Cho phép giảm số chunk đưa vào prompt, nên tiết kiệm token và giảm nhiễu cùng lúc.Lets you send fewer chunks to the prompt, saving tokens and cutting noise at once.
  • Cắm được vào mọi retriever hiện có mà không phải re-index gì.Plugs into any existing retriever with no re-indexing required.
  • Model rerank nhỏ (100–500 triệu tham số) chạy được trên phần cứng rẻ.Reranker models are small (100–500M parameters) and run on cheap hardware.

MấtYou lose

  • Thêm khoảng 50–300 ms mỗi truy vấn cho 20–100 ứng viên, ngay trên đường đi của người dùng.Adds roughly 50–300 ms per query for 20–100 candidates, right on the user's critical path.
  • Chi phí tăng tuyến tính theo số ứng viên, nên không thể rerank cả corpus.Cost grows linearly with candidate count, so you can never rerank the whole corpus.
  • Không cứu được tài liệu đã rớt khỏi top-k của tầng một.It cannot rescue a document that already fell out of stage one's top-k.
  • API rerank thương mại tính tiền theo từng request search và tăng theo số tài liệu gửi lên, nên rất dễ đội chi phí.Commercial rerank APIs bill per search request, scaled by how many documents you send, which makes overspending easy.
  • Thêm một phụ thuộc mạng có thể chậm hoặc chết vào đường đi nóng.It puts one more network dependency, able to slow down or die, on the hot path.

Dấu hiệu nhận biếtHow to tellTài liệu đúng nằm ở hạng 12–40, chứ không phải nằm ngoài top-50.The correct document sits at rank 12–40, rather than outside the top 50 entirely.

06

Hybrid SearchHybrid Search

Truy xuấtRetrieval

Trộn tìm kiếm từ khoá với tìm kiếm vector.Blends keyword and vector search.

Chạy song song BM25 (từ khoá, chính xác mặt chữ) và vector (ngữ nghĩa), rồi trộn hai danh sách. Cách trộn mặc định tốt là RRF, vì nó chỉ dùng thứ hạng và do đó tránh được việc so hai thang điểm không cùng đơn vị.Run BM25 (keyword, exact on surface form) and vector search (semantic) in parallel, then merge the two lists. The good default merge is RRF, because it only uses ranks and therefore avoids comparing two scores measured in different units.

        ┌─ BM25   ─► [d3, d9, d1, ...] ─┐
q ──────┤                               ├─► RRF: Σ 1/(60+rank) ─► hợp nhất
        └─ vector ─► [d9, d4, d3, ...] ─┘
                        ▲
        d9 xuất hiện ở cả hai nhánh → nổi lên đầu

Đánh đổiTrade-offChọn hybrid là đổi độ phức tạp vận hành của hai index lấy độ phủ trên cả hai kiểu truy vấn.Choosing hybrid trades the operational complexity of two indexes for coverage across both query styles.

Dùng choUse it for

  • Tài liệu kỹ thuật đầy mã lỗi, tên hàm và số hiệu phiên bản.Technical documentation full of error codes, function names and version numbers.
  • Thương mại điện tử: tên sản phẩm chính xác trộn lẫn mô tả mơ hồ.E-commerce, where exact product names mix with vague descriptions.
  • Y tế và pháp lý, nơi thuật ngữ chuẩn và cách nói dân dã cùng tồn tại.Medicine and law, where formal terminology and everyday speech coexist.
  • Corpus trộn nhiều ngôn ngữ, nơi một nhánh luôn có điểm mù.Mixed-language corpora, where either branch alone has a blind spot.

ĐượcYou gain

  • Gần như luôn tốt hơn hoặc bằng từng nhánh riêng lẻ, thường tăng 8–15% recall.Almost always matches or beats either branch alone, usually adding 8–15% recall.
  • BM25 gần như miễn phí về mặt tính toán so với embedding.BM25 is computationally close to free next to embedding.
  • RRF không có trọng số phải tinh chỉnh, nên chạy được ngay trên tập dữ liệu mới.RRF has no weights to tune, so it works out of the box on a new dataset.
  • Bắt được cả từ hiếm lẫn cách nói vòng mà không cần model lớn hơn.Catches rare tokens and paraphrases without moving to a bigger model.

MấtYou lose

  • Hai index phải xây, đồng bộ và giám sát thay vì một.Two indexes to build, sync and monitor instead of one.
  • BM25 cần tokenizer đúng cho tiếng Việt (tách từ, xử lý dấu); mặc định thường sai.BM25 needs the right tokenizer for Vietnamese (word segmentation, diacritics); the default is usually wrong.
  • Trộn theo trọng số alpha rất nhạy cảm và không chuyển được giữa các tập dữ liệu.Weighted alpha blending is fragile and does not transfer between datasets.
  • Độ trễ bằng nhánh chậm nhất, trừ khi bạn chạy thật sự song song.Latency equals the slowest branch unless you really run them in parallel.
  • Hằng số k = 60 trong RRF là quy ước từ một bài báo, hiếm khi ai kiểm chứng lại trên dữ liệu của mình.The k = 60 constant in RRF is a convention from one paper that almost nobody re-validates on their own data.

Dấu hiệu nhận biếtHow to tellTruy vấn chứa mã hoặc tên riêng thì thất bại, còn truy vấn mô tả thì tốt, hoặc ngược lại.Queries with codes or proper nouns fail while descriptive queries work, or the other way round.

07

Metadata FilteringMetadata Filtering

Truy xuấtRetrieval

Thu hẹp kết quả bằng thẻ.Narrows results with tags.

Ràng buộc cứng áp lên tập ứng viên trước hoặc trong khi tìm: tenant, ngôn ngữ, ngày, quyền truy cập, loại tài liệu. Đây là thứ duy nhất trong mười hai khái niệm có tính đúng-sai tuyệt đối chứ không phải xác suất.A hard constraint applied to the candidate set before or during search: tenant, language, date, access rights, document type. It is the only one of the twelve concepts that is absolutely right or wrong rather than probabilistic.

                ┌──────────── payload filter ────────────┐
q ──►embed──►   │ tenant=acme ∧ lang=vi ∧ date>2024-01   │ ──► ANN chỉ duyệt
                └────────────────────────────────────────┘      phần hợp lệ

post-filter      : ANN top-k rồi mới lọc   → có thể còn quá ít hoặc 0 kết quả
pre-filter thô   : lọc rồi quét brute-force → đúng, nhưng chậm nếu khớp nhiều
                   (hoặc cắt đồ thị HNSW → đứt liên kết, mất recall)
lọc trong index  : lọc NGAY khi duyệt index → mặc định nên dùng

Đánh đổiTrade-offChọn metadata filtering là đổi công sức duy trì lược đồ metadata lấy sự đảm bảo cứng về đúng phạm vi.Choosing metadata filtering trades the effort of maintaining a metadata schema for a hard guarantee about scope.

Dùng choUse it for

  • SaaS nhiều khách hàng, nơi rò rỉ chéo tenant là sự cố bảo mật chứ không phải lỗi chất lượng.Multi-tenant SaaS, where cross-tenant leakage is a security incident, not a quality bug.
  • Tài liệu có phiên bản: chỉ được lấy bản còn hiệu lực.Versioned documents where only the currently effective revision may be retrieved.
  • Phân quyền theo vai trò, ví dụ nhân viên và quản lý thấy hai tập tài liệu khác nhau.Role-based access, where staff and managers see two different document sets.
  • Giới hạn theo thời gian, ví dụ “chính sách áp dụng năm nay”.Time scoping, such as “the policy in force this year”.

ĐượcYou gain

  • Loại bỏ cả một lớp lỗi mà không model nào sửa được.Eliminates an entire class of errors that no model can fix.
  • Thu hẹp không gian tìm kiếm nên thường làm truy vấn nhanh hơn, không phải chậm hơn.Shrinks the search space, so queries usually get faster rather than slower.
  • Là nơi duy nhất cưỡng chế được ACL một cách đáng tin cậy.It is the only place where ACLs can be enforced reliably.
  • Cho phép một index phục vụ nhiều ngữ cảnh và nhiều khách hàng.Lets one index serve many contexts and many customers.

MấtYou lose

  • Chỉ tốt bằng chất lượng metadata; một trường sai còn nguy hiểm hơn không có trường nào.Only as good as the metadata; one wrong field is more dangerous than no field at all.
  • Post-filter (lọc sau khi đã lấy ANN top-k) âm thầm trả về quá ít kết quả, hoặc rỗng, khi bộ lọc hẹp (chỉ khớp ít tài liệu).Post-filtering (filter after the ANN top-k) silently returns too few results, or none, when the filter is selective.
  • Pre-filter kiểu thô hỏng theo chiều ngược lại: quét brute-force tập đã lọc sẽ chậm khi có nhiều tài liệu khớp, còn cắt đồ thị HNSW xuống chỉ phần khớp thì làm đứt liên kết và mất recall. Hãy dùng filtered search của vector database, vốn áp bộ lọc ngay trong lúc duyệt index.Naive pre-filtering hurts the other way: brute-forcing the filtered set is slow when many documents match, and pruning the HNSW graph down to the matches breaks its connectivity and loses recall. Use the vector database's filtered search, which applies the filter during traversal.
  • Mỗi trường lọc mới thường kéo theo một lần re-index.Each new filterable field usually forces another re-index.
  • ACL thay đổi phải đồng bộ được vào index; nếu trễ, hệ thống rò rỉ trong im lặng.ACL changes must propagate into the index; if they lag, the system leaks silently.

Dấu hiệu nhận biếtHow to tellTồn tại một ràng buộc mà nếu sai thì không chấp nhận được, dù kết quả có liên quan đến đâu.There is a constraint that is unacceptable to violate, no matter how relevant the result is.

08

Context WindowContext Window

Sinh & Tin cậyGeneration & Trust

Lượng text mà LLM giữ được.How much text the LLM holds.

Giới hạn cứng về số token model đọc được trong một lần gọi, tính cả system prompt, lịch sử hội thoại, ngữ cảnh truy xuất và phần model sinh ra. Đây là một ràng buộc, không phải một kỹ thuật: bạn quản lý ngân sách chứ không “bật” nó lên.A hard limit on how many tokens the model can read in one call, counting the system prompt, the conversation history, the retrieved context and the output it generates. This is a constraint, not a technique: you manage a budget, you do not switch it on.

│◄──────────────── 128k token ────────────────►│
┌────────┬──────────┬────────────────┬─────────┐
│ system │ history  │  retrieved ctx │ output  │
└────────┴──────────┴────────────────┴─────────┘
   2k         6k        ngân sách còn lại   2k dự trữ

"lost in the middle": phần giữa được chú ý ít nhất
[ đầu ████████  ...  giữa ▁▁▁▁  ...  cuối ██████ ]

Đánh đổiTrade-offChọn nhồi thêm ngữ cảnh là đổi tiền, độ trễ và độ tập trung của model lấy khả năng bao phủ nhiều tài liệu hơn.Choosing to pack in more context trades money, latency and the model's focus for coverage of more documents.

Dùng choUse it for

  • Quyết định đưa ba hay ba mươi chunk vào prompt.Deciding whether to send three chunks or thirty into the prompt.
  • Chatbot nhiều lượt cần cắt bớt lịch sử mà không làm mất mạch hội thoại.Multi-turn chatbots that must trim history without losing the thread.
  • Tóm tắt tài liệu dài hơn cửa sổ bằng chiến lược map-reduce.Summarising documents longer than the window through map-reduce.
  • Quyết định giữa việc làm RAG và việc dán thẳng toàn bộ corpus vào prompt.Deciding between building RAG and simply pasting the whole corpus into the prompt.

ĐượcYou gain

  • Cửa sổ lớn cho phép bỏ hẳn RAG với corpus nhỏ, đổi lấy kiến trúc đơn giản hơn nhiều.A large window lets you drop RAG entirely for small corpora, buying a much simpler architecture.
  • Prompt caching làm phần đầu prompt gần như miễn phí ở những lần gọi lặp lại.Prompt caching makes the prefix nearly free on repeated calls.
  • Nhiều ngữ cảnh hơn làm giảm áp lực phải truy xuất hoàn hảo.More context lowers the pressure to retrieve perfectly.

MấtYou lose

  • Chi phí và độ trễ tăng gần tuyến tính theo số token đầu vào.Cost and latency grow close to linearly with input tokens.
  • Chất lượng không tăng tuyến tính; thêm chunk nhiễu thường làm câu trả lời tệ đi.Quality does not grow linearly; adding noisy chunks usually makes answers worse.
  • Hiệu ứng “lost in the middle” khiến vị trí đặt ngữ cảnh quan trọng ngang nội dung của nó.The “lost in the middle” effect makes placement matter as much as content.
  • Token tiếng Việt đắt hơn tiếng Anh khoảng 1,5–2 lần cho cùng một nội dung.Vietnamese text costs roughly 1.5–2× more tokens than English for the same content.
  • Cửa sổ quảng cáo (một triệu token) hiếm khi giữ được chất lượng ở mức đó trong thực tế.Advertised windows (a million tokens) rarely hold their quality anywhere near that size.

Dấu hiệu nhận biếtHow to tellPrompt bị cắt cụt, chi phí tăng tuyến tính theo số chunk, hoặc chất lượng giảm khi thêm ngữ cảnh.Prompts get truncated, cost rises linearly with chunk count, or quality drops as you add context.

09

Hallucination GuardHallucination Guard

Sinh & Tin cậyGeneration & Trust

Giảm số sự kiện bịa ra.Cuts down invented facts.

Tập kiểm tra chạy trước và sau khi sinh, nhằm phát hiện câu trả lời không được ngữ cảnh chống lưng, rồi chặn hoặc hạ cấp nó. Không phải một model, mà là một cái cổng có nhiều tầng, xếp từ rẻ tới đắt.A set of checks running before and after generation to detect answers the context does not support, then block or downgrade them. Not a model but a gate, built from several layers ordered from cheap to expensive.

điểm truy hồi thấp ──► "Không tìm thấy tài liệu liên quan"   (chặn TRƯỚC)
        │
        ▼
    LLM sinh ──► tách thành các mệnh đề
                      │
        ┌─────────────┼──────────────┐
     có [1] ✓      có [3] ✓      không nguồn ✗
        │             │               │
        └──── giữ ────┘         ──► bỏ / hỏi lại / hạ cấp

Đánh đổiTrade-offChọn hallucination guard là đổi tỷ lệ trả lời lấy độ tin cậy của những câu trả lời còn lại.Choosing a hallucination guard trades answer rate for the trustworthiness of the answers that remain.

Dùng choUse it for

  • Tư vấn y tế, pháp lý hoặc tài chính, nơi một câu sai là rủi ro thật.Medical, legal or financial advice, where one wrong sentence is a real risk.
  • Hệ thống đối mặt khách hàng, nơi câu trả lời sai sẽ bị chụp màn hình.Customer-facing systems, where a wrong answer will be screenshotted.
  • Trợ lý nội bộ được dùng làm căn cứ ra quyết định.Internal assistants used as the basis for decisions.
  • Bất kỳ chỗ nào mà “không biết” tốt hơn “đoán”.Anywhere “I don't know” beats a guess.

ĐượcYou gain

  • Bắt được lớp lỗi nguy hiểm nhất: sai nhưng nghe đúng.Catches the most dangerous class of failure: wrong but plausible.
  • Ngưỡng điểm truy xuất là bộ lọc rẻ nhất và bắt phần lớn ca “không có tài liệu”.A retrieval score threshold is the cheapest filter and catches most “no document” cases.
  • Buộc hệ thống phải có đường thoát “tôi không biết”, thứ mà thiết kế mặc định thường thiếu.Forces the system to have an “I don't know” path, which default designs usually lack.
  • Kiểm tra entailment chạy được bằng model nhỏ, chi phí thấp hơn nhiều so với gọi thêm LLM lớn.Entailment checks run on small models, far cheaper than another large-LLM call.

MấtYou lose

  • Không bộ chặn nào đạt 100%; luôn còn ca lọt.No guard reaches 100%; some cases always slip through.
  • Đánh đổi trực tiếp với tỷ lệ trả lời: chặn chặt quá thì hệ thống thành vô dụng.It trades directly against answer rate: block too hard and the system becomes useless.
  • Dùng một LLM khác để kiểm tra thì chính nó cũng có thể bịa.Using another LLM as the judge means the judge can hallucinate too.
  • Thêm một lượt gọi model nên tăng cả độ trễ lẫn chi phí.It adds another model call, so both latency and cost go up.
  • Ca hallucination (model bịa thông tin) tinh vi nhất là ngữ cảnh đúng nhưng bị diễn giải sai; kiểm tra ở mức câu rất khó bắt.The subtlest hallucination is correct context misread; sentence-level checks rarely catch it.

Dấu hiệu nhận biếtHow to tellModel trả lời trôi chảy và tự tin cho câu hỏi mà corpus không hề chứa đáp án.The model answers fluently and confidently to questions the corpus has no answer for.

10

GroundingGrounding

Sinh & Tin cậyGeneration & Trust

Neo câu trả lời vào nguồn thật.Ties answers to real sources.

Ràng buộc rằng mọi khẳng định trong câu trả lời phải truy ngược được về một đoạn cụ thể trong ngữ cảnh, và người đọc nhìn thấy được liên kết đó. Grounding là bản hợp đồng; hallucination guard là bên thi hành hợp đồng ấy.The rule that every claim in an answer must trace back to a specific passage in the context, and that the reader can see the link. Grounding is the contract; the hallucination guard is what enforces it.

CONTEXT
[1] "Thời hạn hoàn tiền là 30 ngày."   (src: policy.pdf#p4)
[2] "Phí vận chuyển không được hoàn."  (src: policy.pdf#p5)

ANSWER
"Bạn có 30 ngày để hoàn tiền [1]; phí vận chuyển không được hoàn [2]."
                              ▲                                    ▲
                    mỗi câu neo vào một đoạn có thật

Đánh đổiTrade-offChọn grounding là đổi sự trôi chảy và tự do diễn đạt của model lấy khả năng kiểm chứng từng câu.Choosing grounding trades the model's fluency and freedom of expression for sentence-level verifiability.

Dùng choUse it for

  • Mọi trợ lý tài liệu nội bộ, nơi người dùng phải kiểm chứng được câu trả lời.Any internal document assistant where users must be able to verify the answer.
  • Báo cáo tuân thủ bắt buộc dẫn nguồn cho từng khẳng định.Compliance reporting that requires a source for every claim.
  • Sản phẩm nghiên cứu và tổng hợp tài liệu.Research and literature-synthesis products.
  • Bất kỳ chỗ nào người dùng sẽ hành động dựa trên câu trả lời.Anywhere a user will act on the answer.

ĐượcYou gain

  • Biến câu trả lời không kiểm chứng được thành thứ kiểm chứng được trong năm giây.Turns an unverifiable answer into one anybody can check in five seconds.
  • Gián tiếp giảm hallucination vì model bị ép bám vào ngữ cảnh.Indirectly reduces hallucination because the model is pinned to the context.
  • Trích dẫn tạo niềm tin nhanh hơn bất kỳ cải thiện độ chính xác nào.Citations build trust faster than any accuracy improvement.
  • Cho phép người dùng tự phát hiện lỗi hệ thống thay vì âm thầm tin theo.Lets users catch system errors instead of quietly believing them.

MấtYou lose

  • Model vẫn có thể gắn trích dẫn sai cho một câu đúng, và ngược lại.The model can still attach the wrong citation to a right sentence, and the reverse.
  • Trích dẫn giả — số đoạn không tồn tại — xảy ra thường xuyên nếu không kiểm tra bằng code.Fabricated citations — passage numbers that do not exist — are common unless code checks them.
  • Grounding chặt làm câu trả lời cứng, rời rạc và kém trôi chảy.Strict grounding makes answers stiff, choppy and less readable.
  • Không bảo vệ được gì khi chính tài liệu nguồn đã sai.It protects nothing when the source document itself is wrong.
  • Tăng token đầu ra và tăng độ phức tạp của giao diện hiển thị.It increases output tokens and the complexity of the display layer.

Dấu hiệu nhận biếtHow to tellNgười dùng hỏi “lấy ở đâu ra?” và hệ thống không trả lời được.A user asks “where did that come from?” and the system cannot answer.

11

Data DriftData Drift

Vận hànhOperations

Nguồn thay đổi, index thành cũ.Sources change; the index goes stale.

Nguồn thay đổi nhưng index thì không, nên hệ thống trả lời tự tin bằng sự thật của tháng trước. Có hai dạng: drift nội dung (tài liệu bị sửa hoặc xoá) và drift phân bố (kiểu câu hỏi và từ vựng của người dùng đổi, khiến embedding cũ kém hợp).The source changes but the index does not, so the system confidently answers with last month's truth. Two kinds exist: content drift (documents edited or deleted) and distribution drift (user vocabulary and question styles shift, so the old embeddings fit worse).

t0   nguồn: [A v1][B v1][C]        index: [A v1][B v1][C]      ✓ khớp
t1   nguồn: [A v2][ xoá ][C][D]    index: [A v1][B v1][C]      ✗ lệch
               │      │                          │
             sửa    xoá                   thiếu D, còn B "ma"

phát hiện: hash(doc) ≠ hash đang lưu trong index

Đánh đổiTrade-offChọn đồng bộ liên tục là đổi một khoản chi phí vận hành thường trực lấy việc câu trả lời còn đúng sau sáu tháng.Choosing continuous syncing trades a permanent operational cost for answers that are still correct six months later.

Dùng choUse it for

  • Tài liệu chính sách hoặc bảng giá thay đổi hàng tháng.Policy documents or price lists that change monthly.
  • Wiki nội bộ có nhiều người cùng sửa.Internal wikis edited by many people.
  • Catalog sản phẩm với hàng thêm, hàng ngừng bán.Product catalogues with items added and discontinued.
  • Tài liệu kỹ thuật đi theo phiên bản phần mềm.Technical documentation versioned alongside software releases.

ĐượcYou gain

  • Đồng bộ theo hash rẻ hơn re-index toàn bộ hàng chục lần.Hash-based syncing is an order of magnitude cheaper than full re-indexing.
  • Xử lý xoá đúng cách loại bỏ lớp lỗi tệ nhất: trả lời bằng tài liệu đã bị thu hồi.Handling deletes properly removes the worst failure mode: answering from a withdrawn document.
  • Theo dõi drift phân bố cảnh báo sớm trước khi người dùng kịp phàn nàn.Tracking distribution drift warns you before users start complaining.
  • Buộc bạn lưu timestamp trong payload, thứ sau này dùng được cho cả lọc lẫn xếp hạng.It forces timestamps into the payload, which later serve both filtering and ranking.

MấtYou lose

  • Xoá là phần khó nhất và bị bỏ quên nhiều nhất trong mọi pipeline ingest.Deletion is the hardest and most forgotten part of any ingest pipeline.
  • Nhiều nguồn không có API “cái gì đã đổi”, buộc phải quét toàn bộ định kỳ.Many sources have no “what changed” API, forcing periodic full scans.
  • Đổi model embedding bắt buộc re-index toàn corpus, không có đường tắt.Changing the embedding model requires re-indexing everything; there is no shortcut.
  • Hệ thống không hỏng ồn ào; nó xuống cấp lặng lẽ nên rất khó phát hiện.The system does not fail loudly; it degrades quietly, which makes it hard to notice.
  • Cần một golden set chạy định kỳ, và chính golden set đó cũng cũ dần theo thời gian.You need a golden test set on a schedule, and that set goes stale too.

Dấu hiệu nhận biếtHow to tellCâu trả lời đúng lúc ra mắt và sai dần sau hai, ba tháng mà không ai đổi một dòng code.Answers are right at launch and drift wrong over two or three months with no code change.

12

Knowledge GraphKnowledge Graph

Nạp & Biểu diễnIngest & Representation

Thực thể liên kết cho ngữ cảnh giàu hơn.Linked entities add richer context.

Biểu diễn tri thức bằng nút (thực thể) và cạnh có nhãn (quan hệ). Nó trả lời được những câu hỏi phải đi qua nhiều bước — thứ mà tìm kiếm theo độ tương đồng về bản chất không làm được, vì đáp án không nằm gọn trong bất kỳ chunk nào.Knowledge represented as nodes (entities) and labelled edges (relations). It answers questions that require several hops — something similarity search fundamentally cannot do, because the answer does not sit inside any single chunk.

      (Acme) ──mua_lại[2023]──► (Beta) ──sở_hữu──► (Sáng chế X)
         │                                              ▲
    giám_đốc                                            │
         ▼                                       cấp_phép_cho
      (Lan) ──────────ký─────────► (Hợp đồng 44) ───────┘

hỏi: "Acme gián tiếp kiểm soát sáng chế nào?"  → 2 bước, không mảnh nào chứa

Đánh đổiTrade-offChọn knowledge graph là đổi một chi phí xây dựng và bảo trì rất lớn lấy khả năng trả lời câu hỏi nhiều bước.Choosing a knowledge graph trades a very large build and maintenance cost for the ability to answer multi-hop questions.

Dùng choUse it for

  • Điều tra tuân thủ và cấu trúc sở hữu doanh nghiệp.Compliance investigations and corporate ownership structures.
  • Hồ sơ bệnh án nối triệu chứng, thuốc và tương tác thuốc.Patient records linking symptoms, drugs and interactions.
  • Phân tích phụ thuộc trong một hệ thống phần mềm lớn.Dependency analysis across a large software system.
  • Câu hỏi tổng hợp trên toàn corpus, ví dụ “chủ đề nào lặp lại nhiều nhất”.Corpus-wide synthesis questions such as “which theme recurs most”.

ĐượcYou gain

  • Trả lời được câu hỏi nhiều bước mà vector search về nguyên tắc không thể.Answers multi-hop questions that vector search cannot reach in principle.
  • Quan hệ tường minh nên đường suy luận kiểm tra được, không phải tin vào model.Relations are explicit, so the reasoning path is inspectable rather than trusted.
  • Khử trùng lặp thực thể: “Acme”, “Acme Corp”, “ACME Inc.” gộp về một nút.Entity resolution collapses “Acme”, “Acme Corp” and “ACME Inc.” into one node.
  • Kết hợp với vector search (GraphRAG) thường vượt trội ở câu hỏi tổng hợp toàn corpus.Combined with vector search (GraphRAG) it clearly wins on corpus-wide synthesis questions.

MấtYou lose

  • Chi phí xây dựng cao nhất trong mười hai khái niệm; trích xuất quan hệ bằng LLM vừa tốn tiền vừa sai nhiều.The highest build cost of the twelve; LLM relation extraction is both expensive and error-prone.
  • Lược đồ quan hệ phải thiết kế trước và rất khó đổi về sau.The relation schema must be designed up front and is painful to change later.
  • Liên kết thực thể là một bài toán khó riêng; sai một chỗ làm hỏng cả vùng đồ thị.Entity linking is a hard problem of its own; one mistake corrupts a whole region of the graph.
  • Thêm một cơ sở dữ liệu nữa để vận hành, sao lưu và giám sát.It adds another database to run, back up and monitor.
  • Với phần lớn ứng dụng RAG, lợi ích không bù được chi phí.For most RAG applications the benefit does not cover the cost.

Dấu hiệu nhận biếtHow to tellCâu hỏi cần nối ít nhất hai sự kiện nằm ở hai tài liệu khác nhau.The question requires joining at least two facts that live in two different documents.

Bảng đánh đổiTrade-off table

Khái niệmConceptChi phí thêmAdded costĐộ trễ thêmAdded latencyMức cải thiệnTypical gainĐộ khó vận hànhOps burdenBỏ qua được khiSkip it when
01 Vector Embeddings01 Vector EmbeddingsThấp, trả một lần mỗi chunkLow, paid once per chunk+5–20 ms+5–20 msNền tảng của mọi thứ còn lạiFoundation for everything elseThấpLowNgười dùng luôn gõ đúng thuật ngữUsers always type the exact term
02 Vector Database02 Vector DatabaseTrung bình (RAM và hosting)Medium (RAM and hosting)+10–50 ms+10–50 msCho phép mở rộng quy môMakes scale possibleTrung bình đến caoMedium to highDưới ~100k vectorUnder ~100k vectors
03 Semantic Search03 Semantic SearchThấp (là ứng dụng của 01+02)Low (an application of 01+02)——+20–40% recall khi hỏi tự do+20–40% recall on free-form questionsThấpLowTruy vấn toàn mã và tên riêngQueries are all codes and names
04 Chunking04 ChunkingRất thấpVery low00Cao nhất trên mỗi đồng bỏ raHighest return per unit of effortThấp, nhưng đổi = re-indexLow, but changing it means re-indexingKhông bao giờNever
05 Re-ranking05 Re-rankingTrung bình, tính theo từng request search (tăng theo số tài liệu)Medium, billed per search request (scaled by document count)+50–300 ms+50–300 ms+10–25 nDCG@5+10–25 nDCG@5ThấpLowrecall@50 đang thấprecall@50 is already low
06 Hybrid Search06 Hybrid SearchThấpLow+10–30 ms+10–30 ms+8–15% recall+8–15% recallTrung bình (hai index)Medium (two indexes)Corpus không có từ hiếmThe corpus has no rare tokens
07 Metadata Filtering07 Metadata FilteringRất thấpVery lowThường âm (nhanh hơn)Usually negative (faster)Đúng/sai tuyệt đốiAbsolutely right or wrongTrung bình (chất lượng metadata)Medium (metadata quality)Một tenant, không phân quyềnSingle tenant, no access control
08 Context Window08 Context WindowCao, tuyến tính theo tokenHigh, linear in tokensCaoHighCó ngưỡng, vượt qua thì âmHas a ceiling, then turns negativeThấpLowKhông bỏ qua được — là ràng buộcCannot be skipped — it is a constraint
09 Hallucination Guard09 Hallucination GuardTrung bìnhMedium+50–300 ms+50–300 msGiảm 30–70% ca bịa30–70% fewer invented answersTrung bìnhMediumRủi ro thấp, người dùng tự kiểmLow stakes, users verify themselves
10 Grounding10 GroundingRất thấpVery low≈ 0≈ 0Kiểm chứng được từng câuSentence-level verifiabilityThấpLowBản dùng thử nội bộInternal prototype
11 Data Drift11 Data DriftThường trựcContinuous00Giữ hệ thống khỏi mục dầnKeeps the system from rottingCaoHighCorpus đóng băngThe corpus is frozen
12 Knowledge Graph12 Knowledge GraphRất caoVery high+50–200 ms+50–200 msChỉ ở câu hỏi nhiều bướcOnly on multi-hop questionsRất caoVery highCâu hỏi chỉ cần một bướcQuestions need a single hop

Anti-patternsAnti-patterns

Sai lầmMistakeVì sao saiWhy it is wrongSửa thế nàoHow to fix it
Cắt cố định 512 token, bỏ qua cấu trúcFixed 512-token cuts that ignore structureCắt ngang bảng, điều khoản và câu điều kiện; embedding của một chunk cụt không đại diện cho gì cảSevers tables, clauses and conditional sentences; the embedding of a fragment represents nothingCắt theo cấu trúc trước; số token chỉ là giới hạn trênSplit by structure first; token count is only a ceiling
Nhồi 30 chunk vào prompt cho chắcStuffing 30 chunks into the prompt to be safeNhiễu áp đảo tín hiệu, phần giữa bị bỏ qua, tiền tăng gấp sáuNoise drowns signal, the middle is ignored, and cost rises sixfoldRerank rồi lấy 3–5 chunk; đo điểm khi giảm số chunkRerank, then send 3–5 chunks; measure the score as you cut
Đặt ngưỡng cosine cứng, ví dụ 0,75A hard cosine threshold such as 0.75Điểm không hiệu chuẩn, khác nhau giữa từng truy vấn và từng modelScores are uncalibrated and vary by query and by modelDùng thứ hạng; nếu buộc phải có ngưỡng thì hiệu chuẩn trên golden set của mìnhUse rank; if you must have a threshold, calibrate it on your own golden set
Chỉ dùng vector search cho corpus đầy mã lỗi và SKUVector-only search over a corpus full of error codes and SKUsEmbedding làm nhoè token hiếm, đúng chỗ nó cần chính xác nhấtEmbeddings smear rare tokens exactly where precision matters mostThêm BM25 và trộn bằng RRFAdd BM25 and merge with RRF
Không xử lý xoá khi đồng bộIgnoring deletions during syncHệ thống trả lời bằng tài liệu đã bị thu hồi và không ai phát hiệnThe system answers from withdrawn documents and nobody noticesĐối chiếu hai chiều giữa nguồn và index theo lịchReconcile source and index in both directions on a schedule
Lọc tenant hoặc ACL ở phía clientFiltering tenant or ACL on the clientRò rỉ dữ liệu chéo khách hàng — sự cố bảo mật, không phải lỗi chất lượngCross-customer data leakage — a security incident, not a quality bugCưỡng chế bộ lọc ở server, ngay trong truy vấn indexEnforce the filter on the server, inside the index query
Đánh giá bằng cách hỏi thử vài câu thấy ổnEvaluating by trying a few questions that felt fineKhông phát hiện được hồi quy, không biết thay đổi nào thật sự có íchRegressions go undetected and you never learn which change helpedGolden set 50–100 câu, đo recall@k và nDCG@5 mỗi lần đổiA 50–100 question golden set, with recall@k and nDCG@5 measured on every change
Fine-tune model để dạy nó tài liệu nội bộFine-tuning the model to teach it internal documentsĐắt, cập nhật chậm, vẫn bịa, và không trích dẫn được nguồnExpensive, slow to update, still hallucinates, and cannot cite anythingRAG cho sự thật; fine-tune chỉ cho phong cách và định dạngRAG for facts; fine-tuning only for style and format
Xây knowledge graph ngay từ sprint đầuBuilding a knowledge graph in the first sprintTiêu hết ngân sách vào phần có lợi ích nhỏ nhất và chi phí lớn nhấtSpends the whole budget on the smallest benefit and the largest costLàm baseline BM25 hoặc vector trước; chỉ thêm KG khi có bằng chứng câu hỏi nhiều bướcShip a BM25 or vector baseline first; add a graph only with evidence of multi-hop questions
Trộn nhiều model embedding trong một indexMixing several embedding models in one indexHai không gian vector không so sánh được, kết quả trở nên vô nghĩaThe two vector spaces are not comparable, so results become meaninglessMột index, một model, ghim phiên bản vào từng bản ghiOne index, one model, with the version pinned into every record
Chỉ lưu vector, không lưu text gốcStoring vectors without the original textKhông hiển thị được trích dẫn và không gỡ lỗi được bất cứ thứ gìYou cannot show citations and you cannot debug anythingLuôn lưu text, nguồn và vị trí trong payloadAlways keep the text, the source and the location in the payload
Trả lời “tôi không biết” mà không nói vì saoSaying “I don't know” without saying whyNgười dùng mất niềm tin và quay lại tìm tayUsers lose trust and go back to searching by handNói rõ đã tìm ở đâu và gợi ý cách hỏi khácState where you looked and suggest a different way to ask

Ba câu cần nhớThree things to remember

  1. Chất lượng RAG được quyết định ở khâu truy xuất, không phải khâu sinh: nếu tài liệu đúng không nằm trong top-k, không prompt nào cứu được.RAG quality is decided in retrieval, not generation: if the right document is not in the top k, no prompt can save you.
  2. Chunking và metadata là hai quyết định rẻ nhất nhưng ảnh hưởng lớn nhất — làm đúng hai thứ đó trước khi nghĩ tới rerank hay knowledge graph.Chunking and metadata are the cheapest decisions with the biggest impact — get both right before considering reranking or a knowledge graph.
  3. Không có golden set thì bạn không cải thiện hệ thống, bạn chỉ đang thay đổi nó ngẫu nhiên.Without a golden test set you are not improving the system, you are changing it at random.