-- Chunking test -- This test verifies text chunking functionality -- Test with short text (should return 1 chunk) SELECT array_length( pgedge_vectorizer.chunk_text( 'This is a short test.', 'token_based', 100, 10 ), 1 ) AS num_chunks; -- Test with longer text (should return multiple chunks) SELECT array_length( pgedge_vectorizer.chunk_text( repeat('This is a test sentence that will be repeated many times to create a long text. ', 50), 'token_based', 100, 20 ), 1 ) >= 2 AS has_multiple_chunks; -- Test that chunks are returned SELECT length(chunk) > 0 AS chunk_not_empty FROM unnest( pgedge_vectorizer.chunk_text( 'Test content for chunking', 'token_based', 100, 10 ) ) AS chunk LIMIT 1; -- Test default parameters SELECT array_length( pgedge_vectorizer.chunk_text( 'Test with default parameters' ), 1 ) AS chunks_with_defaults; -- Test overlap chunking - verify chunks don't start mid-word -- This tests the bug fix for corrupted chunks when overlap > 0 SELECT chunk, -- Verify chunk starts with a letter or quote (not mid-word) substring(chunk, 1, 1) ~ '^[A-Za-z"'']' AS starts_properly FROM unnest( pgedge_vectorizer.chunk_text( 'This is the first sentence. This is the second sentence. This is the third sentence. This is the fourth sentence.', 'token_based', 10, 2 ) ) AS chunk; -- Test zero overlap (should work correctly) SELECT chunk, substring(chunk, 1, 1) ~ '^[A-Za-z"'']' AS starts_properly FROM unnest( pgedge_vectorizer.chunk_text( 'First sentence here. Second sentence here. Third sentence here.', 'token_based', 5, 0 ) ) AS chunk; -- Test large overlap (50%) SELECT array_length( pgedge_vectorizer.chunk_text( 'The quick brown fox jumps over the lazy dog. The quick brown fox jumps again.', 'token_based', 8, 4 ), 1 ) >= 1 AS large_overlap_works;