Исходный код СУБД 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
-- Vectorization test
-- This test verifies enable/disable vectorization functionality
-- Create a test table
CREATE TABLE test_docs (
    id BIGSERIAL PRIMARY KEY,
    title TEXT,
    content TEXT
);
-- Enable vectorization
SELECT pgedge_vectorizer.enable_vectorization(
    'test_docs'::regclass,
    'content',
    'token_based',
    100,
    10,
    1536
);
NOTICE:  Using primary key column: id (bigint)
NOTICE:  Vectorization enabled: test_docs -> test_docs_content_chunks
NOTICE:  Strategy: token_based, chunk_size: 100, overlap: 10
NOTICE:  Processing existing rows...
NOTICE:  Processed 0 existing rows
 enable_vectorization 
----------------------
 
(1 row)
 
-- Verify chunk table was created
SELECT tablename FROM pg_tables
WHERE tablename = 'test_docs_content_chunks';
        tablename         
--------------------------
 test_docs_content_chunks
(1 row)
 
-- Verify trigger was created
SELECT tgname FROM pg_trigger
WHERE tgname LIKE '%test_docs%vectorization%';
                 tgname                  
-----------------------------------------
 test_docs_content_vectorization_trigger
(1 row)
 
-- Insert a test document
INSERT INTO test_docs (title, content)
VALUES ('Test Document', 'This is a test document with some content for testing the vectorization functionality.');
-- Verify chunks were created
SELECT COUNT(*) > 0 AS chunks_created FROM test_docs_content_chunks;
 chunks_created 
----------------
 t
(1 row)
 
-- Verify queue entries were created
SELECT COUNT(*) > 0 AS queue_entries_created
FROM pgedge_vectorizer.queue
WHERE chunk_table = 'test_docs_content_chunks';
 queue_entries_created 
-----------------------
 t
(1 row)
 
-- Test update (should recreate chunks)
UPDATE test_docs SET content = 'Updated content for the test document.' WHERE id = 1;
-- Disable vectorization
SELECT pgedge_vectorizer.disable_vectorization('test_docs'::regclass, 'content', false);
NOTICE:  Vectorization disabled (chunk table preserved): test_docs_content_chunks
 disable_vectorization 
-----------------------
 
(1 row)
 
-- Verify trigger was dropped
SELECT COUNT(*) AS trigger_count FROM pg_trigger
WHERE tgname LIKE '%test_docs%vectorization%';
 trigger_count 
---------------
             0
(1 row)
 
-- Verify queue items were cleaned up
SELECT COUNT(*) AS orphaned_queue_items
FROM pgedge_vectorizer.queue
WHERE chunk_table = 'test_docs_content_chunks'
AND status IN ('pending', 'processing');
 orphaned_queue_items 
----------------------
                    0
(1 row)
 
-- Re-enable vectorization with existing chunk table (should not fail)
SELECT pgedge_vectorizer.enable_vectorization(
    'test_docs'::regclass,
    'content',
    'token_based',
    100,
    10,
    1536
);
NOTICE:  Using primary key column: id (bigint)
NOTICE:  relation "test_docs_content_chunks" already exists, skipping
NOTICE:  relation "test_docs_content_chunks_embedding_idx" already exists, skipping
NOTICE:  relation "test_docs_content_chunks_source_id_idx" already exists, skipping
NOTICE:  Vectorization enabled: test_docs -> test_docs_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 trigger was re-created
SELECT tgname FROM pg_trigger
WHERE tgname LIKE '%test_docs%vectorization%';
                 tgname                  
-----------------------------------------
 test_docs_content_vectorization_trigger
(1 row)
 
-- Verify chunks still exist (upserted, not duplicated)
SELECT COUNT(*) AS chunk_count FROM test_docs_content_chunks;
 chunk_count 
-------------
           1
(1 row)
 
-- Clean up
SELECT pgedge_vectorizer.disable_vectorization('test_docs'::regclass, 'content', true);
NOTICE:  Vectorization disabled and chunk table dropped: test_docs_content_chunks
 disable_vectorization 
-----------------------
 
(1 row)
 
DROP TABLE test_docs;