pg_summarize

Text Summarization using LLMs. Built using pgrx

Overview

PackageVersionCategoryLicenseLanguage
pg_summarize0.0.1RAGPostgreSQLRust
IDExtensionBinLibLoadCreateTrustRelocSchema
1860pg_summarizeNoYesNoYesNoNo-
Relatedvectorize pg_tiktoken pg4ml pgml vector vchord vectorscale pg_net

PG18 fix by https://github.com/Vonng/pg_summarize

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY0.0.11817161514pg_summarize-
RPMPIGSTY0.0.11817161514pg_summarize_$v-
DEBPIGSTY0.0.11817161514postgresql-$v-pg-summarize-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
d13.x86_64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
d13.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
u22.x86_64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
u22.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
u24.x86_64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
u24.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1

Build

You can build the RPM / DEB packages for pg_summarize using pig build:

pig build pkg pg_summarize         # build RPM / DEB packages

Install

You can install pg_summarize directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pg_summarize;          # Install for current active PG version
pig ext install -y pg_summarize -v 18  # PG 18
pig ext install -y pg_summarize -v 17  # PG 17
pig ext install -y pg_summarize -v 16  # PG 16
pig ext install -y pg_summarize -v 15  # PG 15
pig ext install -y pg_summarize -v 14  # PG 14
dnf install -y pg_summarize_18       # PG 18
dnf install -y pg_summarize_17       # PG 17
dnf install -y pg_summarize_16       # PG 16
dnf install -y pg_summarize_15       # PG 15
dnf install -y pg_summarize_14       # PG 14
apt install -y postgresql-18-pg-summarize   # PG 18
apt install -y postgresql-17-pg-summarize   # PG 17
apt install -y postgresql-16-pg-summarize   # PG 16
apt install -y postgresql-15-pg-summarize   # PG 15
apt install -y postgresql-14-pg-summarize   # PG 14

Create Extension:

CREATE EXTENSION pg_summarize;

Usage

pg_summarize: Text Summarization using LLMs, built using pgrx. Source: README.md

pg_summarize is a PostgreSQL extension written in Rust (using pgrx) that integrates with the OpenAI API. It includes a basic “Hello, pg_summarize!” function and a summarize function that summarizes text using OpenAI’s models.


Getting Started

CREATE EXTENSION pg_summarize;

-- Test the hello function
SELECT hello_pg_summarize();
--  hello_pg_summarize
-- ----------------------
--  Hello, pg_summarize

Configuration

The extension retrieves configuration from PostgreSQL settings. Set the following before using the summarize function:

-- Set the OpenAI API key (required)
ALTER SYSTEM SET pg_summarizer.api_key = 'your_openai_api_key';

-- Optionally set the model (default: gpt-3.5-turbo)
ALTER SYSTEM SET pg_summarizer.model = 'gpt-3.5-turbo';

-- Or set the prompt at session level
SET pg_summarizer.prompt = 'Your custom prompt here';

-- Reload the configuration if set at SYSTEM level
SELECT pg_reload_conf();

Summarize Function

The summarize function takes text input, sends it to the OpenAI API, and returns a summary:

-- Summarize a text input
SELECT summarize('<This is the text to be summarized.>');

-- Create a summary table from existing data
CREATE TABLE blogs_summary AS
  SELECT blog_url, summarize(blogs_text)
  FROM hexacluster_blogs;

-- Use a different model
SET pg_summarizer.model = 'gpt-4o';
CREATE TABLE blogs_summary_4o AS
  SELECT blog_url, summarize(blogs_text)
  FROM hexacluster_blogs;

How It Works

  • Configuration Retrieval: The summarize function retrieves settings (API key, model, prompt) from PostgreSQL using current_setting(). Defaults are used if settings are not found.
  • Default Prompt: A built-in prompt instructs the AI to summarize text from <text> tags, focusing on capturing the most important information concisely.
  • API Call: The function sends a POST request to the OpenAI chat completions endpoint with the configured model and prompt, returning the summary content.

Last Modified 2026-03-12: add pg extension catalog (95749bf)