Logo Ai Rag Patterns

Ai Rag Patterns

Cộng đồng
peterbamuhigire
ai-rag-patterns

Dùng khi xây dựng tính năng trả lời câu hỏi dựa trên dữ liệu riêng tư, tài liệu, chính sách hoặc thông tin có giới hạn thời gian — kiến trúc RAG, chia đoạn, tìm kiếm kết hợp, xếp hạng lại, cơ sở dữ liệu vector, đánh giá, RAG dạng tác nhân và đa phương thức, cùng truy xuất lặp có giới hạn cho các tác nhân phụ thiếu ngữ cảnh.

Add to TypingMind

Tổng quan

Nhà phát hànhpeterbamuhigire
Kho mãchwezi-dev-engine
Tên kỹ năngai-rag-patterns
Sao
29
Bản fork
6
Tệp đi kèm
8
Giấy phépMIT
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • 8 tệp đi kèm

    Các tập lệnh, mẫu và tài liệu tham khảo mà mô hình có thể đọc khi làm việc. Các tệp chỉ cho phép đọc và không bao giờ được thực thi.

  • Mã nguồn mở

    Được peterbamuhigire công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Ai Rag Patterns trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/peterbamuhigire/chwezi-dev-engine/tree/main/skills/ai/ai-rag-patterns
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/peterbamuhigire/chwezi-dev-engine.git /tmp/chwezi-dev-engine
mkdir -p .claude/skills
cp -r /tmp/chwezi-dev-engine/skills/ai/ai-rag-patterns .claude/skills/ai-rag-patterns
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Ai Rag Patterns trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp Ai Rag Patterns ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng Ai Rag Patterns với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

RAG Patterns — Retrieval-Augmented Generation

Operating contract

Inputs

InputRequiredPurpose
Domain evidenceyesquestion set, authoritative corpus, tenancy and access rules, freshness target, citation needs, and evaluation set

Outputs

  • Produce: retrieval architecture, ingestion/chunking policy, index and filter contract, grounded-answer schema, and evaluation report.

Capability and permission boundaries

Default to read-only analysis. Read only scoped records; redact secrets and regulated data. Writes, execution, network calls, production configuration, customer communication, billing changes, and delegation require explicit authority and an identified owner. Never widen tenant, time-window, or system scope implicitly.

Degraded mode

When required telemetry, evidence, execution, network access, or write authority is unavailable, return a partial result with each unassessed item labelled, preserve the safest existing state, and state the evidence or approval needed to continue. Never convert missing evidence into a pass.

Decision rules

ConditionAction
Scope, owner, or threshold is missingStop the affected decision and request it
Evidence is incomplete but read-only analysis is safeProduce a qualified partial result and gap list
A mutation exceeds authority or tenant boundaryBlock it and route for approval
Evidence meets the stated thresholdIssue the output with provenance and owner

Anti-Patterns

  • Treating absent evidence as success. Fix: mark the check unassessed and name the missing source.
  • Expanding one tenant or workflow to all tenants. Fix: enforce supplied scope at every query and action.
  • Performing a production write during analysis. Fix: emit a reviewed change plan until authority is explicit.
  • Reporting a metric without population, window, or source. Fix: attach all three.
  • Hiding a failed threshold inside an average. Fix: report failure slices and the remediation owner.

Acknowledgement: Shared by Peter Bamuhigire, techguypeter.com, +256 784 464178.

Use When

  • Use when building features that answer questions from private data, documents, policies, or time-sensitive information — RAG architecture, chunking strategies, hybrid search, re-ranking, vector databases, evaluation, agentic RAG, multimodal RAG...

Evidence Produced

CategoryArtifactFormatExample
CorrectnessRAG retrieval evaluation reportMarkdown doc covering recall / precision / answer-quality on a fixed eval setdocs/ai/rag-eval-2026-04-16.md
Data safetyIndex ingestion + tenancy isolation noteMarkdown doc covering chunking, source filtering, and per-tenant index segregationdocs/ai/rag-tenancy-note.md

References

  • Use the references/ directory for deep detail after reading the core workflow below.
  • references/curated-corpus-worked-example.md: small curated corpus with BM25 ranking, per-domain score floors, calibrated abstention and a graded, fingerprinted golden set.

Overview

RAG solves the core LLM limitation: they only know what they were trained on. Use RAG to inject private data (invoices, menus, policies, reports) into every AI response.

Core principle: RAG = look up a database + LLM synthesises the results. The LLM never needs to "know" your data.


When to Use RAG

ConditionAction
Knowledge base < 200K tokens (~500 pages)Include everything in context — no RAG needed
Knowledge base > 200K tokensUse RAG
Data changes frequently (menus, prices, stock)RAG (update documents, not model)
Data is private/confidentialRAG (keeps data out of training pipelines)
Need source citationsRAG (chunks are traceable to source)
Model needs brand voice / domain jargonFine-tune instead

RAG vs Fine-Tuning

FactorRAGFine-Tuning
Up-to-date content✅ Yes (add docs anytime)❌ Stale until retrained
Hallucinations✅ Lower (document-grounded)❌ Higher
Source citations✅ Yes❌ No
Brand voice control❌ Weak✅ Strong
Domain jargon❌ Weak✅ Strong
Up-front cost✅ Lower❌ High

Default: start with RAG. Fine-tune only when RAG + prompt engineering cannot deliver the required tone or vocabulary.


Additional Guidance

Guidance is split across two reference files so this entrypoint stays compact.

references/skill-deep-dive.md — architecture, chunking, retrieval, schema:

  • Pipeline Architecture
  • Chunking Strategies
  • Embedding Model Selection
  • Vector Database Selection
  • Retrieval Algorithms
  • Re-Ranking
  • Full RAG Query Algorithm
  • Query Rewriting (Multi-Turn)
  • RAG Schema (Multi-Tenant)
  • Evaluation Framework
  • Production Patterns
  • Agentic RAG
  • Multimodal RAG, Edge Cases, Cost Optimisation, Sources

references/production-rag.md — the progression from draft to production and the gates before shipping:

  • RAG Maturity Model — Naive → Advanced → Modular
  • Query Transformation — HyDE, Multi-Query, Step-Back
  • Contextual Compression
  • Self-RAG
  • RAGAS Evaluation — 4 metrics with production thresholds
  • Embedding Pipeline — batching, upserts, re-embed triggers, $/1M-token table
  • Cost Management Decision Tree — concrete dollar figures per branch
  • Failure Mode Playbook — empty, irrelevant, hallucinated, stale
  • Gates Before Shipping

references/iterative-retrieval.md — load when a context-starved subagent must explore a codebase or workspace before working: bounded DISPATCH-EVALUATE-REFINE-LOOP (max 3 cycles), relevance banding, explicit gap lists, and terminology learning.

Load the production file when building a RAG system that has to pass evaluation gates, survive multi-tenant review, or hit a cost budget under load.

When answers depend on structured records about a specific customer, order or account (not documents), or when embedding, prompt and model versions must be managed like an ML system, load python-ml-predictive reference ml-system-architecture-fti.md (feature/training/inference pipelines, entity-keyed retrieval, version coupling).

Multi-Tenant Addendum

This skill describes RAG patterns in general. When the RAG feature ships inside a multi-tenant SaaS, the production answer is ai-rag-multi-tenant — per-tenant ingestion pipelines, vector store partitioning, tier-specific chunking and embedding models, defence-in-depth retrieval security, and citation grounding tied to live sources.

Cross-references:

  • ai-rag-multi-tenant — multi-tenant RAG end-to-end.
  • ai-tenant-isolation-patterns — vector-store partitioning tradeoffs and data-bleed tests.
  • ai-on-saas-architecture — KB service as a control-plane service.
  • ai-hallucination-slo-and-grounding — citation grounding + faithfulness SLO.
  • ai-model-gateway — gateway-mediated retrieval calls.
  • saas-tenant-data-portability-and-erasure — KB erasure cascade for embeddings.
  • Catalog metadata for AI — load when retrieval or an agent draws on data-catalog or data-contract metadata: classification-first filtering, ODCS context block, provenance.

Consolidated Child References

Tệp đi kèm

Khi kỹ năng đã được tải, mô hình có thể đọc các tệp này nếu cần. Các tệp này chỉ dùng để đọc và không bao giờ được thực thi.

Câu hỏi thường gặp

Kỹ năng AI Ai Rag Patterns làm được gì?

Dùng khi xây dựng tính năng trả lời câu hỏi dựa trên dữ liệu riêng tư, tài liệu, chính sách hoặc thông tin có giới hạn thời gian — kiến trúc RAG, chia đoạn, tìm kiếm kết hợp, xếp hạng lại, cơ sở dữ liệu vector, đánh giá, RAG dạng tác nhân và đa phương thức, cùng truy xuất lặp có giới hạn cho các tác nhân phụ thiếu ngữ cảnh.

Vì sao nên dùng Ai Rag Patterns trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Ai Rag Patterns là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Ai Rag Patterns trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/peterbamuhigire/chwezi-dev-engine/tree/main/skills/ai/ai-rag-patterns. TypingMind đọc tệp SKILL.md, đóng gói các tệp đi kèm rồi cài đặt cả gói dưới dạng một kỹ năng mà bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Ai Rag Patterns?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng Ai Rag Patterns với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Ai Rag Patterns với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Ai Rag Patterns có miễn phí không?

Có. Kỹ năng này được peterbamuhigire phát hành trên GitHub theo giấy phép MIT. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇