rag-chunking-strategy-advisor
Given a document type and retrieval goal, recommends the optimal chunking strategy for a RAG pipeline to minimize retrieval failures.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Given a document type and retrieval goal, recommends the optimal chunking strategy for a RAG pipeline to minimize retrieval failures.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Runs a systematic checklist review on any code diff or file, covering correctness, security, performance, and readability.
Writes a high-quality CLAUDE.md, .cursorrules, or .windsurfrules file that gives a coding agent the right project context, conventions, and constraints to work effectively.
Designs an eval suite for an LLM agent or pipeline including success metrics, trajectory scoring, LLM-as-judge setup, and regression test cases.
Designs a hybrid retrieval pipeline combining dense vector search and BM25 sparse search with reciprocal rank fusion, and explains when to use each configuration.
Converts a workflow description into a LangGraph node/edge graph with typed state, conditional routing, and human-in-the-loop checkpoints.
Audits an AI application for unnecessary token spend and recommends prompt caching, model routing, and token reduction techniques to cut costs.
| name | RAG Chunking Strategy Advisor |
| description | Given a document type and retrieval goal, recommends the optimal chunking strategy for a RAG pipeline to minimize retrieval failures. |
| category | coding |
| tags | ["rag","chunking","retrieval","embeddings","vector-search"] |
| author | simplyutils |
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.
Copy this file to .agents/skills/rag-chunking-advisor/SKILL.md in your project root.
Then ask:
Provide:
Paste the instructions below along with your document type and retrieval use case.
When asked to advise on RAG chunking, follow these steps:
Ask or infer:
| 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:
chunk_size=512, overlap=50.\n\n, then \n, then ., then . Preserves paragraph structure. Best default for general text.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.
For long structured documents, use a two-level hierarchy:
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])
Before deploying, run this checklist:
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.