agentleFS
Goodnight77Goodnight77/rag-skills/skills/chunking/sliding-window-chunking/SKILL.md

sliding-window-chunking

Skill8 starsChanged 7 months agoMITView on GitHub

Use overlapping windows to preserve context across chunk boundaries while controlling retrieval size.

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 6 are distinctive, and 0 are 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.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Create chunks with configurable overlap.

    line 39
  2. Distinctive:

    When using semantic search where retrieval might match content near boundaries

    line 62
  3. Distinctive:

    When building systems that benefit from multiple retrieval paths

    line 64
  4. Distinctive:

    When storage costs are critical (overlap increases storage 20-30%)

    line 68
  5. Distinctive:

    When exact deduplication is required (overlap makes this harder)

    line 69
  6. Distinctive:

    When using exact keyword search where overlap doesn't help

    line 71

≈ “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

Sliding window chunking creates overlapping chunks where each chunk shares content with adjacent chunks. This preserves context at chunk boundaries, ensuring that information split across chunks remains accessible through multiple retrieval paths.

Problem Statement

Non-overlapping chunking creates hard boundaries that can break important context:

  • Critical information appears exactly at a chunk boundary
  • Concepts spanning multiple chunks become fragmented
  • Retrieval may miss relevant content because it's split across boundaries
  • LLMs lose context when only one fragment is provided

Key Concepts

  • Overlap Percentage: The proportion of shared content between adjacent chunks (typically 10-25%)
  • Window Size: The total size of each chunk including overlap
  • Stride: The distance between chunk start points (window size - overlap)
  • Context Preservation: Ensuring relevant context exists on both sides of boundaries
  • Multiple Retrieval Paths: Same content accessible from different chunks

Implementation Guide

Step 1: Determine Overlap Parameters

Calculate appropriate overlap based on your use case and chunk size.

Why: The overlap ratio determines how much context is preserved - too little loses context, too much creates redundancy.

Step 2: Implement Sliding Window Chunking

Create chunks with configurable overlap.

Why: Boundary adjustment prevents chunks from ending mid-sentence while maintaining the sliding window pattern.

Step 3: Add Chunk Metadata

Track overlap information for retrieval-time decisions.

Why: Metadata allows retrieval systems to identify and deduplicate overlapping content.

Step 4: Implement Smart Retrieval

Handle overlapping results intelligently.

Why: Smart retrieval prevents redundant information while preserving the benefits of overlapping chunks.

Step 5: Token-Aware Sliding Window

Implement sliding window based on tokens rather than characters.

Why: Token-aware chunking is more accurate for LLMs and respects their actual token limits.

Useful implementations include LangChain RecursiveCharacterTextSplitter, the OpenAI tiktoken cookbook, tiktoken, and Sentence Transformers rerankers.

When to Use This Skill

  • Documents where context at boundaries is important
  • When using semantic search where retrieval might match content near boundaries
  • For narrative or sequential content where flow matters
  • When building systems that benefit from multiple retrieval paths
  • For technical documentation where definitions/examples might span chunks

When NOT to Use This Skill

  • When storage costs are critical (overlap increases storage 20-30%)
  • When exact deduplication is required (overlap makes this harder)
  • For structured data with clear boundaries (JSON, CSV)
  • When using exact keyword search where overlap doesn't help

Related Skills

  • Semantic Chunking - For content-aware boundaries
  • Hierarchical Chunking - For nested structures
  • Hybrid Search BM25 Dense - For combining search methods

Metrics & Success Criteria

  • Boundary Coverage: Critical terms appear in at least one chunk (not lost at boundaries)
  • Storage Overhead: Overlap increases storage by expected ratio (e.g., 20%)
  • Retrieval Recall: Same content accessible through multiple chunks
  • Context Preservation: Retrieved chunks contain sufficient surrounding context
  • Deduplication Quality: Can identify and handle overlapping content effectively

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.