一键导入
contextual-chunk-headers
Add higher-level context to chunks by prepending headers before embedding for better retrieval.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Add higher-level context to chunks by prepending headers before embedding for better retrieval.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use this skill when building, debugging, or improving Retrieval-Augmented Generation systems, including chunking, vector database selection, hybrid search, reranking, multimodal RAG, code documentation RAG, retrieval latency, and production RAG architecture.
Chunk nested documents into parent-child levels so retrieval can move from broad sections to fine-grained passages.
Use semantic boundaries and embedding similarity to chunk text for higher-relevance retrieval.
Route RAG chunking decisions across semantic, hierarchical, sliding-window, contextual-header, and framework-selection strategies.
Use overlapping windows to preserve context across chunk boundaries while controlling retrieval size.
Reduce retrieval latency with caching, batching, and index-level optimization.
| name | contextual-chunk-headers |
| title | Contextual Chunk Headers |
| description | Add higher-level context to chunks by prepending headers before embedding for better retrieval. |
| allowed-tools | ["Read","Grep","Glob","Bash"] |
| category | chunking |
| tags | ["contextual-headers","metadata","chunk-enhancement","document-structure"] |
Contextual chunk headers (CCH) enhance retrieval by prepending higher-level context (document title, section headers, summaries) to each chunk before embedding. This gives embeddings a more accurate representation of content and meaning, significantly improving retrieval quality and reducing irrelevant results.
Individual chunks often lack sufficient context:
Extract or generate document titles and summaries for use in chunk headers.
Why: Document-level context provides the most important higher-level information for understanding any chunk within that document.
Use an LLM to generate a descriptive document title if one doesn't exist, or extract titles from document structure.
Parse document structure to capture section and subsection titles.
Why: Section hierarchy provides granular context that helps retrieve information about specific topics and themes within the document.
Parse the document structure (markdown headings, HTML tags, etc.) to build a hierarchical representation of sections.
Combine document and section context into comprehensive headers.
Why: Combined context provides both broad document understanding and specific section information, giving embeddings the best possible representation.
For each chunk, create a header combining document title and the section path that contains the chunk.
Combine headers with chunk content before embedding.
Why: Embeddings represent the combined header+chunk content, capturing both local meaning and global context in the same vector space.
When indexing each chunk, include the header as a prefix to the chunk content.
Use the header-enhanced chunks for embedding and indexing.
Why: Embedding with headers ensures that retrieval considers both local content and broader context, leading to more relevant matches.
Index the enhanced chunks using your preferred embedding model and vector database.
Include headers when presenting retrieved chunks to users or LLMs.
Why: Presenting headers provides necessary context for understanding retrieved chunks, reducing misinterpretation and improving answer quality.
When returning retrieved content, include the original header for context.
Combine all components into a cohesive chunking and retrieval system.
Why: A complete pipeline ensures that contextual headers are consistently applied through chunking, embedding, retrieval, and presentation.
For implementation patterns, see LangChain RecursiveCharacterTextSplitter, LlamaIndex node parser usage, Anthropic Contextual Retrieval, and dsRAG AutoContext.