Skip to main content

Handling Long Documents in Sonamu

You’re building a feature to upload blog posts or manuals to your Sonamu app:
Problem:
  • Long documents (10,000+ words)
  • Exceeds embedding API token limit
  • Cannot embed the entire document at once
Solution: Chunking - splitting documents into smaller pieces

What is Chunking?

Key points:
  • Long document -> multiple chunks
  • Each chunk -> individual embedding
  • During search -> return the most relevant chunks

Why is it Necessary?

1. Token Limits
  • Voyage AI: 32,000 tokens
  • OpenAI: 8,191 tokens
  • Long documents exceed limits
2. Search Accuracy
  • Shorter chunks yield more accurate results
  • Searching β€œrefund method” -> returns only the refund section
3. Context Preservation
  • Keep related information together
  • Split without breaking sentences

Sonamu’s Chunking Class

Using in Sonamu Model

Long Document Upload + Chunking

Table Structure

Understanding Configuration Options

chunkSize: Chunk Size

Recommended values:
  • Short search: 200-300 characters
  • General: 400-600 characters
  • Long context: 800-1000 characters
Considerations:
  • Korean: ~1 character = ~1 token
  • English: ~1 character = ~0.7 tokens

chunkOverlap: Overlap Size

Purpose: Maintain context at chunk boundaries
Recommended: 10-20% of chunkSize

skipThreshold: Skip Splitting

Efficiency: No chunking needed for short documents

separators: Separator Priority

Behavior: Tries from left to right

Practical Scenarios

Scenario: Technical Documentation Knowledge Base

You’re building a development documentation search system with Sonamu. Step 1: Conditional Chunking
Step 2: Search (Chunk-based)
Response example:

Optimizing for Markdown Documents

Effect: Splits by headings -> preserves context

Chunking vs Full Document

When is Chunking Necessary?

Decision in Sonamu

Cautions

Cautions when using chunking in Sonamu:
  1. Don’t make chunkSize too small
  2. Keep chunkOverlap reasonable
  3. Separator order matters
  4. Maintain parent-child relationship
  5. Remove duplicates when searching
  6. Store offsets (optional)

Next Steps

Vector Search

Implementing chunk-based search API

Embeddings

Generating batch embeddings