Skip to main content

Chunking components for the Sayou Data Platform

Project description

sayou-chunking

PyPI version License Docs

The Intelligent Text Splitter for Sayou Fabric.

sayou-chunking splits large texts into smaller, semantically meaningful units called Chunks. This is a critical step for RAG (Retrieval-Augmented Generation) systems, as it directly impacts retrieval accuracy.

It goes beyond simple character splitting by offering structure-aware, semantic, and hierarchical chunking strategies.

💡 Core Philosophy

"Context is King."

Blindly cutting text at 500 characters breaks sentences and loses meaning. sayou-chunking aims to preserve context by:

  1. Structure Awareness: Respects document headers, tables, and code blocks (especially in Markdown).
  2. Semantic Coherence: Groups sentences that belong to the same topic using similarity metrics.
  3. Hierarchy: Maintains Parent-Child relationships to retrieve small precise chunks while providing large context to the LLM.

📦 Installation

pip install sayou-chunking

⚡ Quick Start

The ChunkingPipeline provides a unified interface for various splitting strategies.

from sayou.chunking.pipeline import ChunkingPipeline

def run_demo():
    # 1. Initialize Pipeline
    pipeline = ChunkingPipeline()
    pipeline.initialize()

    # 2. Prepare Input (e.g., from Refinery)
    text_content = """
    # Section 1: Introduction
    Chunking is the process of breaking text down.
    
    ## Benefits
    - Better Retrieval
    - Context Preservation
    """
    
    request = {
        "content": text_content,
        "metadata": {"source": "doc.md"},
        "config": {"chunk_size": 50}
    }

    # 3. Run with Strategy ('markdown', 'recursive', 'semantic', etc.)
    chunks = pipeline.run(request, strategy="markdown")

    # 4. Result
    for i, chunk in enumerate(chunks):
        print(f"[{i}] Type: {chunk.metadata.get('semantic_type')}")
        print(f"    Content: {chunk.content}")

if __name__ == "__main__":
    run_demo()

🔑 Key Components

Splitter

  • RecursiveSplitter: The standard strategy. Splits by paragraph -> line -> sentence -> word to keep related text together.
  • MarkdownSplitter: Aware of Markdown syntax. Splits by headers (#) first, protecting tables and code blocks.
  • FixedLengthSplitter: Hard split by character count. Useful when strict token limits are required.
  • StructureSplitter: Splits based on user-defined regex patterns (e.g., "Article \d+").
  • SemanticSplitter: Uses cosine similarity between sentences to find topic breakpoints.
  • ParentDocumentSplitter: Creates large "Parent" chunks for context and small "Child" chunks for retrieval, linking them together.

🤝 Contributing

We welcome contributions for New Strategies (e.g., CodeSplitter for Python/JS) or Integrations with other embedding models for Semantic Splitting.

📜 License

Apache 2.0 License © 2025 Sayouzone

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sayou_chunking-0.3.0.tar.gz (22.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sayou_chunking-0.3.0-py3-none-any.whl (24.7 kB view details)

Uploaded Python 3

File details

Details for the file sayou_chunking-0.3.0.tar.gz.

File metadata

  • Download URL: sayou_chunking-0.3.0.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sayou_chunking-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b4597b4142c83e23739af094a6c5605c1169cc4d4ed1b84879e0de9660638009
MD5 81929c7da3f4cddd45b27b8885ac4e9f
BLAKE2b-256 33b10c7db8cdcb8376c39ad89e5fa6e0506781b342106c43cea255e61fefddca

See more details on using hashes here.

File details

Details for the file sayou_chunking-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: sayou_chunking-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 24.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sayou_chunking-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2b16c38eec21c6d91f9e1efbc713c723a6920950537ea835b09f4fb23d38eef1
MD5 271f7230bf7eeebd42d9858d067e4522
BLAKE2b-256 b8eeeec2facbb1277b5989f9120a0a190be18a393860fdd8c31e062718f6cac4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page