Исходный код СУБД 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
-- Maintenance functions test
-- This test verifies reprocess_chunks() and recreate_chunks() functions
-- Create a test table
CREATE TABLE maint_test (
    id BIGSERIAL PRIMARY KEY,
    content TEXT
);
-- Insert test data
INSERT INTO maint_test (content)
VALUES ('Initial content for maintenance testing');
-- Enable vectorization
SELECT pgedge_vectorizer.enable_vectorization(
    'maint_test'::regclass,
    'content',
    'token_based',
    100,
    10,
    1536
);
NOTICE:  Using primary key column: id (bigint)
NOTICE:  Vectorization enabled: maint_test -> maint_test_content_chunks
NOTICE:  Strategy: token_based, chunk_size: 100, overlap: 10
NOTICE:  Processing existing rows...
NOTICE:  Processed 1 existing rows
 enable_vectorization 
----------------------
 
(1 row)
 
-- Verify chunks were created
SELECT COUNT(*) > 0 AS initial_chunks FROM maint_test_content_chunks;
 initial_chunks 
----------------
 t
(1 row)
 
-- Clear embeddings to simulate unprocessed chunks
UPDATE maint_test_content_chunks SET embedding = NULL;
-- Test reprocess_chunks
SELECT pgedge_vectorizer.reprocess_chunks('maint_test_content_chunks') > 0 AS reprocess_queued;
NOTICE:  Queued 0 chunks from maint_test_content_chunks for processing
 reprocess_queued 
------------------
 f
(1 row)
 
-- Verify queue entries were created
SELECT COUNT(*) > 0 AS queue_entries
FROM pgedge_vectorizer.queue
WHERE chunk_table = 'maint_test_content_chunks'
  AND status = 'pending';
 queue_entries 
---------------
 t
(1 row)
 
-- Clean queue for next test
DELETE FROM pgedge_vectorizer.queue WHERE chunk_table = 'maint_test_content_chunks';
-- Add more data
INSERT INTO maint_test (content)
VALUES ('Additional content for recreate testing');
-- Test recreate_chunks
SELECT pgedge_vectorizer.recreate_chunks('maint_test'::regclass, 'content') >= 2 AS recreate_count;
NOTICE:  Recreating chunks for maint_test.content -> maint_test_content_chunks
NOTICE:  Deleted 2 existing chunks
NOTICE:  Cleared queue for maint_test_content_chunks
NOTICE:  Re-chunking with strategy=token_based, size=100, overlap=10
NOTICE:  Processed 2 rows
 recreate_count 
----------------
 t
(1 row)
 
-- Verify chunks exist for both rows
SELECT COUNT(*) >= 2 AS chunks_after_recreate FROM maint_test_content_chunks;
 chunks_after_recreate 
-----------------------
 t
(1 row)
 
-- Verify queue entries were created for all chunks
SELECT COUNT(*) >= 2 AS queue_after_recreate
FROM pgedge_vectorizer.queue
WHERE chunk_table = 'maint_test_content_chunks';
 queue_after_recreate 
----------------------
 t
(1 row)
 
-- Clean up
DELETE FROM pgedge_vectorizer.queue WHERE chunk_table = 'maint_test_content_chunks';
SELECT pgedge_vectorizer.disable_vectorization('maint_test'::regclass, 'content', true);
NOTICE:  Vectorization disabled and chunk table dropped: maint_test_content_chunks
 disable_vectorization 
-----------------------
 
(1 row)
 
DROP TABLE maint_test;