Skip to content

pg_vector_embedding

Trigger-driven vector embedding through external HTTP services and a background queue.

pg_vector_embedding · Trigger-driven vector embedding through external HTTP services and a background queue.

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
101937pg_vector_embeddingpg_vector_embedding1.0.0RAGApache-2.0SQL
Relationships
Requireshttp pg_background_queue vector

Usage

Sources:

pg_vector_embedding Trigger-driven vector embedding through external HTTP services and a background queue.

Enablement

Install the files for the intended server, then create pg_vector_embedding in the target database:

CREATE EXTENSION pg_vector_embedding CASCADE;

The reviewed control or official workflow requires http, pg_background_queue, vector. CASCADE only succeeds when those extension files are already installed on the server.

Core Workflow

The following example is taken from the reviewed upstream documentation. Adapt object names, paths, credentials, and workload values before use.

-- 1. Setup
CREATE EXTENSION pg_vector_embedding CASCADE;

ALTER DATABASE mydb SET pg_vector_embedding.embedding_url = 'https://api.example.com/v1/embeddings';
ALTER DATABASE mydb SET pg_vector_embedding.embedding_api_key = 'sk-xxxxx';

\c  -- Reconnect to apply settings

-- 2. Create and register table
CREATE TABLE articles (
    id SERIAL PRIMARY KEY,
    title TEXT,
    content TEXT,
    embedding VECTOR(1024)
);

SELECT ve_enable('public', 'articles', ARRAY['title', 'content'], 'embedding');

-- 3. Insert data (embeddings computed automatically in background)
INSERT INTO articles (title, content) VALUES
    ('PostgreSQL Extensions', 'Learn how to build powerful PostgreSQL extensions'),
    ('Vector Search', 'Implementing semantic search with pgvector');

-- 4. Wait for background processing (or check if embeddings are ready)
SELECT COUNT(*) FROM articles WHERE embedding IS NOT NULL;

-- 5. Perform similarity search
WITH search_query AS (
    SELECT ve_compute_embedding(
        '{"title":"PostgreSQL","content":"tutorial"}'::text
    ) AS query_embedding
)
SELECT id, title, embedding <-> query_embedding AS distance
FROM articles, search_query
WHERE embedding IS NOT NULL
ORDER BY distance
LIMIT 5;

Main Objects

The reviewed install surface includes these prominent objects:

ObjectKindOperational role
ve_compute_embeddingFUNCTIONCallable function from the reviewed install surface.
ve_enableFUNCTIONCallable function from the reviewed install surface.
ve_triggerFUNCTIONCallable function from the reviewed install surface.
ve_compact_row_dataFUNCTIONCallable function from the reviewed install surface.
ve_disableFUNCTIONCallable function from the reviewed install surface.

Operations and Boundaries

  • Treat extension upgrades as database changes: review the upstream upgrade path, privileges, locks, and backup/restore behavior first.

Table reader