Tutorial 01 — Hello Chunks
On this page
Level: Beginner
Time: ~10 minutes
What You'll Learn
- Create a
ChunkManager - Process your first document
- Read chunk metadata
Step 1 — Install
pip install numpy
# Optional for semantic features:
# pip install sentence-transformers torch
Step 2 — Your First Chunk
from zerda.chunks import MultilanguageTextChunker
chunker = MultilanguageTextChunker()
text = """
The Python programming language was created by Guido van Rossum and
released in 1991. Python emphasizes code readability and simplicity.
It supports multiple programming paradigms including procedural,
object-oriented, and functional programming.
Python has a large standard library and an active community. It is
widely used in web development, data science, artificial intelligence,
and automation. The language uses indentation to define code blocks,
which makes it distinctive among programming languages.
"""
chunks = chunker.chunk(text, source="python_intro.txt")
print(f"Produced {len(chunks)} chunk(s)")
Step 3 — Inspect a Chunk
chunk = chunks[0]
print("=== Chunk ===")
print(f"ID: {chunk.chunk_id}")
print(f"Doc ID: {chunk.doc_id}")
print(f"Chars: {chunk.char_count}")
print(f"Words: {chunk.word_count}")
print(f"Type: {chunk.metadata.chunk_type.value}")
print(f"Position: {chunk.metadata.position} of {chunk.metadata.total_chunks}")
print(f"Score: {chunk.metadata.score:.3f}")
print(f"Keywords: {chunk.metadata.keywords}")
print()
print("Text preview:")
print(chunk.text[:200])
Step 4 — Serialize to JSON
import json
data = [c.to_dict() for c in chunks]
print(json.dumps(data[0], ensure_ascii=False, indent=2))
Step 5 — What Happened?
ChunkManager in AUTO mode used StructureAwareChunker (the default). It:
- Detected
PLAIN_TEXTdocument type (no Markdown/HTML markers). - Split on double newlines (paragraph boundaries).
- Ran
MetadataEnricher— added keywords and importance score. - Ran
Deduplicator— no duplicates found. - Finalized position and total_chunks.