Documentation/Chunking

Chunking

Experimental0 credits

Split text into semantically meaningful chunks with 4 strategies. Character and token are free.

Production Recommendation

This is a direct endpoint for development and testing. For production workloads, use the Data Intelligence Pipeline -- it provides structured Data Packages with quality metrics, is async by default, and is covered by Enterprise SLAs.

Overview

The Chunking service splits text into semantically meaningful segments for granular processing, vector indexing, and RAG pipelines.

**4 strategies:** character (free), token (free), semantic (charged), hybrid (charged)

All strategies automatically detect and preserve Markdown structure, code blocks, heading hierarchies, and section boundaries. Each chunk includes structural metadata: character offsets, token counts, semantic coherence scores, and heading paths.

When to Use

Use chunking when you need to split documents into segments for vector indexing, RAG, or any downstream processing. Place it right after Document Intelligence in your pipeline.

API Reference

POSThttps://api.latence.ai/api/v1/chunking/chunk
Split text into overlapping segments with structural metadata. Supports 4 strategies: character (free), token (free), semantic (charged), hybrid (charged).

Request Parameters

ParameterTypeRequiredDefaultDescription
textstringText to chunk (max 5,000,000 characters)
strategystring
charactertokensemantichybrid
hybridChunking strategy. Character and token are free; semantic and hybrid are charged at $0.10/1M chars.
chunk_sizeinteger512Target chunk size (64-8192). Characters for character/semantic/hybrid, tokens for token strategy.
Range: 64 - 8192
chunk_overlapinteger50Overlap between adjacent chunks
Range: 0 - 8191
min_chunk_sizeinteger64Minimum chunk size — smaller chunks are discarded
Range: 1 - 8192
request_idstringOptional request tracking ID

Response Fields

FieldTypeDescription
successbooleanWhether the request succeeded
data.chunksarrayArray of chunk objects with content, index, start, end, char_count, token_count, semantic_score, section_path
data.num_chunksintegerTotal number of chunks produced
data.strategystringChunking strategy used
data.chunk_sizeintegerTarget chunk size parameter
data.processing_time_msnumberProcessing time in milliseconds
usageobjectCredit usage information

Response Example

200 OKJSON
{
  "success": true,
  "data": {
    "chunks": [
      {
        "content": "Introduction to machine learning...",
        "index": 0,
        "start": 0,
        "end": 512,
        "char_count": 498,
        "token_count": 127,
        "semantic_score": 0.87,
        "section_path": ["Chapter 1", "Section 1.1"]
      }
    ],
    "num_chunks": 42,
    "strategy": "hybrid",
    "chunk_size": 512,
    "processing_time_ms": 45.2
  },
  "usage": { "credits": 0.0 }
}

Error Handling

All errors return a JSON body with error and details fields.

StatusCodeDescription
400MISSING_FIELD

Missing required field: text

The text field is required
400INVALID_STRATEGY

Invalid strategy. Must be character, token, semantic, or hybrid

Unknown chunking strategy
429RATE_LIMITED

Rate limit exceeded

Too many requests — retry after the Retry-After interval

Billing

Pricing Formula

cost = (characters / 1,000,000) × rate (strategy-dependent)

Add-ons & Multipliers

OptionPriceDescription
Character strategyFreeFixed character-length splits
Token strategyFreeToken-boundary splits
Semantic strategy$0.10 / 1M charsEmbedding-based semantic grouping
Hybrid strategy$0.10 / 1M charsCharacter splits refined with semantic coherence

Pricing Examples

Chunk 1M chars (character/token)$0.00
Chunk 1M chars (semantic/hybrid)$0.10
Chunk 10M chars (hybrid)$1.00

Code Examples

from latence import Latence

client = Latence(api_key="YOUR_API_KEY")

# Chunk a document (hybrid strategy)
result = client.experimental.chunking.chunk(
    text="Your document text here...",
    strategy="hybrid",
    chunk_size=512,
)
print(f"{result.data.num_chunks} chunks")
for chunk in result.data.chunks:
    print(f"  [{chunk.index}] {chunk.char_count} chars: {chunk.content[:60]}...")

Explore Tutorials & Notebooks

Deep-dive examples and interactive notebooks in our GitHub repository

View on GitHub

Looking for production-grade processing?

The Data Intelligence Pipeline chains services automatically and returns structured Data Packages.