Enable automatic vectorization for a table column.
SELECT pgedge_vectorizer.enable_vectorization(
source_table REGCLASS,
source_column NAME,
chunk_strategy TEXT DEFAULT NULL,
chunk_size INT DEFAULT NULL,
chunk_overlap INT DEFAULT NULL,
embedding_dimension INT DEFAULT NULL,
chunk_table_name TEXT DEFAULT NULL,
source_pk NAME DEFAULT NULL
);
Parameters:
source_table: Table to vectorizesource_column: Column containing textchunk_strategy: Chunking method (token_based, semantic, markdown)chunk_size: Target chunk size in tokenschunk_overlap: Overlap between chunks in tokensembedding_dimension: Vector dimension. When NULL (the default), the dimension is auto-detected by making a probe call to the configured embedding provider/model. Can be set explicitly to override auto-detection.chunk_table_name: Custom chunk table name (default: {table}_{column}_chunks)source_pk: Primary key column to use as the document identifier in the chunk table. When NULL (the default), the primary key column name and type are auto-detected from the table's primary key index via pg_index. Set explicitly to use a specific column (e.g., 'external_id').Primary Key Handling:
source_pk is NULL, the primary key column name and type are detected from pg_index. The chunk table's source_id column is created with the matching type (e.g., UUID, BIGINT, TEXT, VARCHAR(26)).UUID, BIGSERIAL/BIGINT, SERIAL/INTEGER, TEXT, VARCHAR(n), etc.source_pk to select one column explicitly (e.g., source_pk := 'item_id').source_pk explicitly.source_pk to use a different column than the table's actual primary key (e.g., an external_id UUID column).source_pk must contain globally unique values. The chunk table enforces a UNIQUE(source_id, chunk_index) constraint, so duplicate source_pk values will cause conflicts.Behavior:
Content Handling:
{table}_{column}_chunks) and triggerDisable vectorization for a table column.
SELECT pgedge_vectorizer.disable_vectorization(
source_table REGCLASS,
source_column NAME DEFAULT NULL,
drop_chunk_table BOOLEAN DEFAULT FALSE
);
Parameters:
source_table: Table to disable vectorization onsource_column: Column to disable (NULL = disable all columns)drop_chunk_table: Whether to drop the chunk tableManually chunk text content.
SELECT pgedge_vectorizer.chunk_text(
content TEXT,
strategy TEXT DEFAULT NULL,
chunk_size INT DEFAULT NULL,
overlap INT DEFAULT NULL
);
Returns: TEXT[] array of chunks
Generate an embedding vector from query text.
SELECT pgedge_vectorizer.generate_embedding(
query_text TEXT
);
Parameters:
query_text: Text to generate an embedding forReturns: vector - The embedding vector using the configured provider
Example:
-- Generate an embedding for a search query
SELECT
d.id,
c.content,
c.embedding <=> pgedge_vectorizer.generate_embedding('machine learning tutorials') AS distance
FROM documents d
JOIN documents_content_chunks c ON d.id = c.source_id
ORDER BY distance
LIMIT 5;
Note: This function calls the embedding provider synchronously, so it will wait for the API response. For large-scale batch operations, use the automatic vectorization features instead.
Detect the embedding dimension of the currently configured provider/model.
SELECT pgedge_vectorizer.detect_embedding_dimension();
Returns: INT - The number of dimensions in the embedding vector
This function generates a probe embedding using the configured provider and model, and returns the dimension of the resulting vector. It is called automatically by enable_vectorization() when embedding_dimension is not specified.
Retry failed queue items.
SELECT pgedge_vectorizer.retry_failed(
max_age_hours INT DEFAULT 24
);
Returns: Number of items reset to pending
Remove old completed items from queue.
SELECT pgedge_vectorizer.clear_completed(
older_than_hours INT DEFAULT 24
);
Returns: Number of items deleted
Note: Workers automatically clean up completed items based on pgedge_vectorizer.auto_cleanup_hours. Manual cleanup is only needed if you want to clean up more frequently or if automatic cleanup is disabled.
Queue existing chunks without embeddings for processing.
SELECT pgedge_vectorizer.reprocess_chunks(
chunk_table_name TEXT
);
Parameters:
chunk_table_name: Name of the chunk table to reprocessReturns: Number of chunks queued
Example:sql -- Reprocess chunks that don't have embeddings yet SELECT pgedge_vectorizer.reprocess_chunks('product_docs_content_chunks');
Delete all chunks and recreate from source table (complete rebuild).
SELECT pgedge_vectorizer.recreate_chunks(
source_table_name REGCLASS,
source_column_name NAME
);
Parameters:
source_table_name: Source table with the original datasource_column_name: Column that was vectorizedReturns: Number of source rows processed
Example:sql -- Completely rebuild all chunks and embeddings SELECT pgedge_vectorizer.recreate_chunks('product_docs', 'content');
Note: This function deletes all existing chunks and queue items, then triggers re-chunking and re-embedding for all rows. Use with caution.
Display all pgedge_vectorizer configuration settings.
SELECT * FROM pgedge_vectorizer.show_config();
Returns a table with setting and value columns showing all GUC parameters.
Summary of queue items by status.
SELECT * FROM pgedge_vectorizer.queue_status;
Columns:
chunk_table: Table namestatus: Item statuscount: Number of itemsoldest: Oldest item timestampnewest: Newest item timestampavg_processing_time_secs: Average processing timeFailed items with error details.
SELECT * FROM pgedge_vectorizer.failed_items;
Count of pending items.
SELECT * FROM pgedge_vectorizer.pending_count;