pg_gembed
pg_gembed · Generate embeddings inside PostgreSQL
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 101244 | pg_gembed | pg_gembed | 1.0.0 | RAG | Apache-2.0 | C |
PostgreSQL · 18
| Relationships | |
|---|---|
| Requires | vector |
Usage
Sources:
pg_gembed 1.0.0 generates text, image, and multimodal vector embeddings from SQL by calling the local Rust libgembed core. It supports local or remote pluggable backends and returns the vector type, so the vector extension is a required dependency.
Core Workflow
The backend and model strings select an implementation and model known to libgembed. Model files, network access, credentials, and acceleration requirements depend on that backend.
Important Objects
embed_text(text, text, text)andembed_texts(text, text, text[])embed one or many texts.embed_image(text, text, bytea),embed_images(text, text, bytea[]), and their with-ID variants embed image data.embed_multimodal(text, text, bytea[], text[])combines image and text inputs.embed_image_directory(text, text, text)andembed_image_directories(text, text, text[])read image paths on the database server.input_typeand the scalar/arrayembed(...)overloads dispatch text, image, or image-directory inputs.gembed.embedding_jobsandgembed.job_statusstore and report asynchronous embedding jobs.
Preload and Worker Boundary
Synchronous embedding functions can load the library in a session without a restart. The background job worker is different: _PG_init registers it only while PostgreSQL processes shared_preload_libraries. To use gembed.embedding_jobs, preload pg_gembed and restart PostgreSQL. gembed.embedding_worker_naptime defaults to 10 seconds and gembed.embedding_worker_batch_size defaults to 256; both are reloadable GUCs.
Operational Notes
The control file requires superuser installation and vector; the README lists PostgreSQL 17 or later. The worker in the pinned 1.0.0 source opens a fixed database named joeldiaz, so review or patch that code before relying on asynchronous jobs in another database. Directory functions read server-local paths, and embedding backends may load large models or contact configured gRPC/HTTP services. Size model memory, CPU/GPU use, network exposure, and parallel query behavior on the target system before production use.