agentleFS
Goodnight77Goodnight77/rag-skills/skills/chunking/semantic-chunking/SKILL.md

semantic-chunking

Skill8 starsChanged 7 months agoMITView on GitHub

Use semantic boundaries and embedding similarity to chunk text for higher-relevance retrieval.

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 7 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    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
  1. Distinctive:

    Use sentence boundary detection rather than simple period splitting.

    line 34
  2. Distinctive:

    Why: Document structure often encodes semantic boundaries (chapters, sections, subsections).

    line 46
  3. Distinctive:

    When retrieval quality is more important than fixed-size guarantees

    line 57
  4. Distinctive:

    When using semantic search (vector embeddings) for retrieval

    line 59
  5. Distinctive:

    When you need exact token count guarantees (e.g., for API limits)

    line 65
  6. Distinctive:

    When using exact keyword matching (BM25) where chunk size matters less

    line 67
  7. Distinctive:

    Coverage: No significant information lost in chunk boundaries

    line 77

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Overview

Semantic chunking divides documents into segments based on natural language boundaries and semantic meaning rather than fixed character counts. This approach preserves context integrity and improves retrieval relevance by keeping related ideas together.

Problem Statement

Fixed-size chunking (e.g., 1000 tokens) often cuts through mid-sentence, mid-paragraph, or mid-concept, resulting in:

  • Fragments that lose semantic meaning
  • Context bleeding across unrelated chunks
  • Poor retrieval relevance for semantic search
  • Difficulty for LLMs to understand isolated fragments

Key Concepts

  • Semantic Boundaries: Natural break points in text (paragraphs, sections, sentences)
  • Context Preservation: Keeping related ideas and arguments together
  • Sentence Boundary Detection: Using NLP tools to identify proper sentence ends
  • Paragraph Cohesion: Identifying when a new thought or argument begins
  • Overlapping Windows: Small overlaps to preserve context between adjacent chunks

Implementation Guide

Step 1: Detect Sentence Boundaries

Use sentence boundary detection rather than simple period splitting. This handles abbreviations, decimal numbers, and other edge cases.

Why: Simple period/regex splitting fails on "Dr. Smith", "3.14", "U.S.A.", etc.

Step 2: Group Sentences into Semantic Units

Group sentences into chunks based on semantic cohesion rather than fixed counts.

Why: Similarity-based chunking adapts to document density - dense technical sections get smaller chunks, narrative sections get larger ones.

Step 3: Apply Structure-Based Chunking

Leverage document structure (headings, markdown, HTML tags) to identify natural sections.

Why: Document structure often encodes semantic boundaries (chapters, sections, subsections).

Step 4: Implement Adaptive Sizing

Adjust chunk sizes based on content characteristics (code blocks, lists, tables).

Why: Different content types need different chunking strategies for optimal retrieval.

For practical implementations, compare Sentence-BERT, LlamaIndex Semantic Chunker, LangChain RecursiveCharacterTextSplitter, and spaCy sentence segmentation.

When to Use This Skill

  • Documents with clear semantic structure (articles, reports, documentation)
  • When retrieval quality is more important than fixed-size guarantees
  • For narrative or explanatory content where context matters
  • When using semantic search (vector embeddings) for retrieval
  • For Q&A systems that need coherent context for answers

When NOT to Use This Skill

  • Code repositories where line-level precision matters
  • Log files or structured data with fixed formats
  • When you need exact token count guarantees (e.g., for API limits)
  • Streaming data where chunk boundaries can't be deferred
  • When using exact keyword matching (BM25) where chunk size matters less

Related Skills

  • Hierarchical Chunking - For nested document structures
  • Sliding Window Chunking - For overlapping context preservation
  • Hybrid Search BM25 Dense - Combining search methods

Metrics & Success Criteria

  • Retrieval Relevance: Retrieved chunks should contain complete, self-contained information
  • Context Preservation: Related concepts remain in same chunk
  • Coverage: No significant information lost in chunk boundaries
  • Token Efficiency: Chunks balanced between too small (lossy) and too large (noisy)
  • Semantic Coherence: Chunks represent coherent thoughts or sections

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.