Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
-- 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;