rag-patterns
Skill0 starsChanged 8 months agoMITView on GitHub
Retrieval-Augmented Generation design — when to use it, chunking, embeddings, hybrid search, reranking, grounding, and evaluation. Use when building Q&A over documents, knowledge assistants, or any LLM feature grounded in private data.
In this repository25 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- api-patternsSkill
- architectureSkill
- brainstormingSkill
- clean-codeSkill
- code-review-checklistSkill
- database-designSkill
- data-engineeringSkill
- frontend-designSkill
- llm-evaluationSkill
- mcp-builderSkill
- memory-managementSkill
- react-best-practicesSkill
- nodejs-best-practicesSkill
- observabilitySkill
- parallel-agentsSkill
- powershell-windowsSkill
- prompt-engineeringSkill
- python-patternsSkill
- seo-fundamentalsSkill
- systematic-debuggingSkill
- tdd-workflowSkill
- vulnerability-scannerSkill
- webapp-testingSkill
- web-design-guidelinesSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 36
Keep metadata (source, section, date) on every chunk — needed for filtering and citations.
- Distinctive: line 55
Keep the most relevant chunks first.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
RAG Patterns
Ground model answers in your data instead of its memory.
Overview
RAG retrieves relevant context at query time and feeds it to the model, so answers reflect your corpus and can cite sources. The hard part is retrieval quality — the model can only be as good as what you give it.
Do You Even Need RAG?
| Need | Approach |
| Answer over a private/changing corpus | RAG |
| Whole corpus fits in the context window and is small/stable | Long-context (skip retrieval) |
| Change behavior/format/tone, not knowledge | Fine-tune / prompt, not RAG |
| Real-time facts (prices, status) | Tool/API call, not RAG |
The Pipeline
ingest → chunk → embed → store → retrieve → (rerank) → assemble context → generate → citeChunking
- Split on semantic boundaries (headings, paragraphs), not fixed byte counts.
- Typical chunk: a few hundred tokens with small overlap; tune to your content.
- Keep metadata (source, section, date) on every chunk — needed for filtering and citations.
Retrieval
| Technique | Use for |
| Vector (semantic) search | Meaning/paraphrase matches |
| Keyword (BM25) search | Exact terms, codes, names, acronyms |
| Hybrid (vector + keyword) | Default — combines both, usually best recall |
| Reranking (cross-encoder) | Reorder top-N for precision before sending to the model |
| Metadata filters | Scope by tenant, date, permission — apply before/with search |
Improve recall with query rewriting (expand/clarify the user question) and multi-query retrieval when questions are short or ambiguous.
Generation & Grounding
- Instruct the model to answer only from the provided context and to say so when the context is insufficient.
- Require citations back to chunk metadata so answers are verifiable.
- Keep the most relevant chunks first; don't overstuff context (recall ≠ relevance).
Evaluation
| Layer | Question | Metric |
| Retrieval | Did we fetch the right chunks? | recall@k, hit rate |
| Generation | Is the answer supported by context? | faithfulness / groundedness |
| End-to-end | Is the answer correct & useful? | answer relevance (often LLM-as-judge) |
(Use the llm-evaluation skill for the harness.)
Failure Modes
| Symptom | Likely cause |
| Right docs exist but not retrieved | Bad chunking / vector-only search → add keyword/hybrid + rerank |
| Retrieves docs but answer is wrong | Context overstuffed or not instructed to ground → trim, demand citations |
| Confident wrong answers | No "insufficient context" path → add an explicit out |
| Stale answers | Re-embedding not triggered on source change → wire ingestion to updates |
Anti-Patterns
| ❌ | ✅ |
| Fixed-size byte chunks | Semantic chunks + metadata |
| Vector search only | Hybrid + reranking |
| No citations | Cite chunk sources |
| No retrieval evals | Measure recall before blaming the model |
Most RAG quality problems are retrieval problems. Fix retrieval first.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

