RAG Chunking Strategy Advisor
Skill9 starsChanged 8 months agoMITView on GitHub
Given a document type and retrieval goal, recommends the optimal chunking strategy for a RAG pipeline to minimize retrieval failures.
In this repository61 other files it gives its agents.
- Accessibility Audit HelperSkill
- Agent Context File WriterSkill
- Agent Evaluation Framework BuilderSkill
- AI Feature Spec WriterSkill
- API Documentation GeneratorSkill
- REST API Endpoint DesignerSkill
- Architecture ExplainerSkill
- Article RepurposerSkill
- Auth Flow PlannerSkill
- Blog Outline GeneratorSkill
- Breaking Change DetectorSkill
- Bug Root Cause AnalyzerSkill
- Caching Strategy AdvisorSkill
- Changelog CuratorSkill
- Code Review ChecklistSkill
- Database Schema ReviewerSkill
- Docker Compose GeneratorSkill
- Documentation Gap FinderSkill
- Edge Case DiscoverySkill
- Error Log SummarizerSkill
- FAQ GeneratorSkill
- Flaky Test AnalyzerSkill
- Form UX OptimizerSkill
- Git Commit WriterSkill
- Hallucination Risk ReviewerSkill
- Hybrid Search ArchitectSkill
- Incident Postmortem WriterSkill
- Issue to PR PlannerSkill
- Landing Page Copy ImproverSkill
- LangGraph State Machine DesignerSkill
- LLM Cost OptimizerSkill
- LLM Tracing and Observability SetupSkill
- MCP Integration AssistantSkill
- MCP Server BuilderSkill
- Migration Guide WriterSkill
- Newsletter Summary WriterSkill
- Observability ChecklistSkill
- Playwright Test BuilderSkill
- PR Description WriterSkill
- Prompt Injection Defense AuditorSkill
- Prompt RefinerSkill
- Prompt Version Control WorkflowSkill
- RAG Workflow PlannerSkill
- React Component ReviewerSkill
- README WriterSkill
- Refactor PlannerSkill
- Release Notes GeneratorSkill
- Responsive Layout ReviewerSkill
- SDK Quickstart WriterSkill
- SEO Content OptimizerSkill
- SEO Metadata GeneratorSkill
- Social Post Thread WriterSkill
- Sprint Summary GeneratorSkill
- SQL Query OptimizerSkill
- Stack Trace AnalyzerSkill
- Technical Blog Post WriterSkill
- Tech Debt AuditorSkill
- Troubleshooting Guide BuilderSkill
- Unit Test ImproverSkill
- Unit Test WriterSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 6 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 31
Document type (PDFs, markdown, HTML, code, emails, etc.)
- Distinctive: line 42
When asked to advise on RAG chunking, follow these steps:
- Distinctive: line 75
Every chunk must carry metadata for filtering and re-ranking:
- Very specific: line 88
Always store: source, page_or_line, section_heading (if available), doc_type.
- Distinctive: line 106
Before deploying, run this checklist:
- Distinctive: line 115
Splitting tables row-by-row: when the header row is in a different chunk — always keep headers with data rows
- Distinctive: line 117
Chunking code by line count: instead of by function — always use AST-aware splitting for code
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 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 Chunking Strategy Advisor
What this skill does
This skill analyzes your document types, content structure, and retrieval goals to recommend the right chunking strategy for your RAG pipeline. Poor chunking is the #1 cause of RAG failures — chunks too large lose precision, chunks too small lose context. This skill picks the right strategy and explains exactly how to implement it.
How to use
Claude Code / Cline
Copy this file to .agents/skills/rag-chunking-advisor/SKILL.md in your project root.
Then ask:
- "Use the RAG Chunking Strategy Advisor to help me chunk our legal contract PDFs."
- "What chunking strategy should I use for markdown documentation with code blocks?"
Provide:
- Document type (PDFs, markdown, HTML, code, emails, etc.)
- Typical document length
- What users will search for (questions, keywords, concepts)
- Your embedding model if known
Cursor / Codex
Paste the instructions below along with your document type and retrieval use case.
The Prompt / Instructions for the Agent
When asked to advise on RAG chunking, follow these steps:
Step 1 — Identify document characteristics
Ask or infer:
- Document type: structured (tables, headers) vs. unstructured (prose) vs. code
- Length: short (< 1 page), medium (1–20 pages), long (20+ pages)
- Internal structure: does it have headers, sections, numbered lists, code blocks?
- Query type: factual lookups, conceptual questions, code search, or multi-hop reasoning?
Step 2 — Select the primary chunking strategy
| Document Type | Recommended Strategy | Chunk Size |
| Prose (articles, books) | Sentence-window or recursive character | 512–1024 tokens |
| Structured docs (markdown, HTML) | Header-based (split on H2/H3) | Full section |
| PDFs with mixed content | Semantic chunking + page boundary | 512 tokens |
| Source code | Function/class boundary splitting | Full function |
| Tables / spreadsheets | Row-level or table-level | 1 row or full table |
| Emails / short messages | Document-level (no chunking) | Full doc |
| Legal / contracts | Clause-level splitting | 256–512 tokens |
Strategies explained:
- Fixed-size with overlap — Split every N tokens with a 10–20% overlap. Fast, simple, works for uniform prose. Use
chunk_size=512, overlap=50. - Recursive character splitting — Split on
\n\n, then\n, then., then. Preserves paragraph structure. Best default for general text. - Header-based (Markdown/HTML) — Split on heading tags (H1/H2/H3). Each section becomes a chunk with its heading prepended. Best for docs sites and wikis.
- Semantic chunking — Use an embedding model to detect topic shifts; split when cosine similarity drops. Best quality, highest cost. Use when documents have abrupt topic changes.
- Sentence-window — Store sentences as chunks but retrieve surrounding N sentences for context. Good for Q&A over dense technical content.
- Function-level (code) — Use AST parsing to split on function/class boundaries. Never split mid-function.
Step 3 — Configure chunk metadata
Every chunk must carry metadata for filtering and re-ranking:
{
"chunk_id": "doc_001_chunk_004",
"source": "contracts/nda-2024.pdf",
"page": 3,
"section": "Confidentiality Obligations",
"doc_type": "legal",
"created_at": "2024-11-01"
}Always store: source, page_or_line, section_heading (if available), doc_type.
Step 4 — Add a parent-child chunk structure (for complex docs)
For long structured documents, use a two-level hierarchy:
- Parent chunks (1024–2048 tokens): stored for context retrieval
- Child chunks (128–256 tokens): used for embedding and search
Retrieve by child similarity, return parent for context. This avoids the precision vs. context tradeoff.
# LlamaIndex example
from llama_index.node_parser import HierarchicalNodeParser
parser = HierarchicalNodeParser.from_defaults(chunk_sizes=[2048, 512, 128])Step 5 — Validate with retrieval testing
Before deploying, run this checklist:
- Sample 20 real user queries against your chunked index
- Check if the correct chunk appears in top-3 results
- Verify chunk boundaries don't cut mid-sentence or mid-table
- Ensure no chunk is under 50 tokens (too small = noise)
- Ensure no chunk is over 2048 tokens (too large = diluted embedding)
Common chunking mistakes to flag
- Splitting tables row-by-row when the header row is in a different chunk — always keep headers with data rows
- Not adding overlap on fixed-size splits — 10% overlap prevents losing context at boundaries
- Chunking code by line count instead of by function — always use AST-aware splitting for code
- Ignoring document structure — a 500-token chunk that spans two unrelated sections is worse than two 250-token single-topic chunks
Example
Input:
"Use the RAG Chunking Advisor. I'm building a support chatbot. Documents are markdown product docs, 5–30 pages each, with H2 and H3 headers. Users ask specific how-to questions."
Output:
Recommended strategy: Header-based chunking
Split on H2 headers as primary boundaries, H3 as secondary. Each chunk = one section, with its full heading path prepended (
Product > Installation > macOS Setup).Config:
from langchain.text_splitter import MarkdownHeaderTextSplitter splitter = MarkdownHeaderTextSplitter( headers_to_split_on=[("##", "section"), ("###", "subsection")] )Add metadata:
{"source": filename, "section": heading_path, "doc_type": "product_docs"}If sections exceed 800 tokens, apply a secondary recursive split with
chunk_size=600, overlap=60.Validate: run your top 20 support questions against the index and confirm the relevant section appears in top-3.
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.

