-- 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;
|