Skip to main content

chunk()

The chunk() function splits a given text into chunks of a specified size. It provides options for customizing the chunking process and returns the resulting chunks as rows in a table-like format.

Syntax

SELECT * FROM chunk(raw_text, type => ChunkingType)

Parameters

ParameterTypeOptionalDescriptionPossible ValuesSample Value
raw_textStringNoThe raw text which needs to be chunkedAny String'In a quaint village...'
typeStringNoUnit of chunkingChar, Word, Sentence, Paragraph'Char'
chunk_sizeIntYesNumber of units to be present in a ChunkAny non-negative integer100
overlapIntYesNumber of units to overlap between consecutive chunksAny non-negative integer20
trimBoolYesWhether to trim whitespace from the start and end of each chunktrue, falsetrue

Usage

Chunking Raw text into Char with Chunk Size

SELECT * FROM chunk('In a quaint village nestled in the heart of the countryside, there lived a young girl named Lily. She was known throughout the village for her vibrant imagination and her love for adventure. Every day, Lily would set out to explore the lush forests and rolling hills that surrounded her home, always eager to discover something new and exciting.

One particularly sunny morning, Lily decided to venture deeper into the woods than she ever had before. As she walked, she stumbled upon a hidden grove filled with the most beautiful flowers she had ever seen. The colors were so vivid and the petals so delicate that Lily couldnt help but marvel at their beauty. She spent hours in the grove, carefully examining each flower and breathing in their sweet fragrance.',
type => 'Char',
trim => true,
chunk_size => 200);
textindex
In a quaint village nestled in the heart of the countryside, there lived a young girl named Lily. She was known throughout the village for her vibrant imagination and her love for adventure.0
Every day, Lily would set out to explore the lush forests and rolling hills that surrounded her home, always eager to discover something new and exciting.1
One particularly sunny morning, Lily decided to venture deeper into the woods than she ever had before.2
As she walked, she stumbled upon a hidden grove filled with the most beautiful flowers she had ever seen.3
The colors were so vivid and the petals so delicate that Lily couldnt help but marvel at their beauty.4
She spent hours in the grove, carefully examining each flower and breathing in their sweet fragrance.5

Chunking Raw text into Word with Chunk Size and Overlap

SELECT * FROM chunk('In a quaint village nestled in the heart of the countryside, there lived a young girl named Lily. She was known throughout the village for her vibrant imagination and her love for adventure. Every day, Lily would set out to explore the lush forests and rolling hills that surrounded her home, always eager to discover something new and exciting.

One particularly sunny morning, Lily decided to venture deeper into the woods than she ever had before. As she walked, she stumbled upon a hidden grove filled with the most beautiful flowers she had ever seen. The colors were so vivid and the petals so delicate that Lily couldnt help but marvel at their beauty. She spent hours in the grove, carefully examining each flower and breathing in their sweet fragrance.',
type => 'Word',
chunk_size => 30,
overlap => 10);
textindex
In a quaint village nestled in the heart of the countryside there lived a young girl named Lily She was known throughout the village for her vibrant imagination and her0
known throughout the village for her vibrant imagination and her love for adventure Every day Lily would set out to explore the lush forests and rolling hills that surrounded her1
explore the lush forests and rolling hills that surrounded her home always eager to discover something new and exciting

One particularly sunny morning Lily decided to venture deeper into the

2
particularly sunny morning Lily decided to venture deeper into the woods than she ever had before As she walked she stumbled upon a hidden grove filled with the most beautiful3
stumbled upon a hidden grove filled with the most beautiful flowers she had ever seen The colors were so vivid and the petals so delicate that Lily couldnt help but4
and the petals so delicate that Lily couldnt help but marvel at their beauty She spent hours in the grove carefully examining each flower and breathing in their sweet fragrance5

Chunking Raw text into Sentence

SELECT * FROM chunk('In a quaint village nestled in the heart of the countryside, there lived a young girl named Lily. She was known throughout the village for her vibrant imagination and her love for adventure. Every day, Lily would set out to explore the lush forests and rolling hills that surrounded her home, always eager to discover something new and exciting.

One particularly sunny morning, Lily decided to venture deeper into the woods than she ever had before. As she walked, she stumbled upon a hidden grove filled with the most beautiful flowers she had ever seen. The colors were so vivid and the petals so delicate that Lily couldnt help but marvel at their beauty. She spent hours in the grove, carefully examining each flower and breathing in their sweet fragrance.',
type => 'Sentence');
textindex
In a quaint village nestled in the heart of the countryside, there lived a young girl named Lily0
She was known throughout the village for her vibrant imagination and her love for adventure1
Every day, Lily would set out to explore the lush forests and rolling hills that surrounded her home, always eager to discover something new and exciting2
One particularly sunny morning, Lily decided to venture deeper into the woods than she ever had before3
As she walked, she stumbled upon a hidden grove filled with the most beautiful flowers she had ever seen4
The colors were so vivid and the petals so delicate that Lily couldnt help but marvel at their beauty5
She spent hours in the grove, carefully examining each flower and breathing in their sweet fragrance6

Chunking Raw text into Paragraph

SELECT * FROM chunk('In a quaint village nestled in the heart of the countryside, there lived a young girl named Lily. She was known throughout the village for her vibrant imagination and her love for adventure. Every day, Lily would set out to explore the lush forests and rolling hills that surrounded her home, always eager to discover something new and exciting.

One particularly sunny morning, Lily decided to venture deeper into the woods than she ever had before. As she walked, she stumbled upon a hidden grove filled with the most beautiful flowers she had ever seen. The colors were so vivid and the petals so delicate that Lily couldnt help but marvel at their beauty. She spent hours in the grove, carefully examining each flower and breathing in their sweet fragrance.',
type => 'Paragraph');
textindex
In a quaint village nestled in the heart of the countryside, there lived a young girl named Lily. She was known throughout the village for her vibrant imagination and her love for adventure. Every day, Lily would set out to explore the lush forests and rolling hills that surrounded her home, always eager to discover something new and exciting.0
One particularly sunny morning, Lily decided to venture deeper into the woods than she ever had before. As she walked, she stumbled upon a hidden grove filled with the most beautiful flowers she had ever seen. The colors were so vivid and the petals so delicate that Lily couldnt help but marvel at their beauty. She spent hours in the grove, carefully examining each flower and breathing in their sweet fragrance.1