pg_summarize
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_summarize | 0.0.1 | RAG | PostgreSQL | Rust |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 1860 | pg_summarize | No | Yes | No | Yes | No | No | - |
| Related | vectorize pg_tiktoken pg4ml pgml vector vchord vectorscale pg_net |
|---|
PG18 fix by https://github.com/Vonng/pg_summarize
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.0.1 | 1817161514 | pg_summarize | - |
| RPM | PIGSTY | 0.0.1 | 1817161514 | pg_summarize_$v | - |
| DEB | PIGSTY | 0.0.1 | 1817161514 | postgresql-$v-pg-summarize | - |
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
summarizefunction retrieves settings (API key, model, prompt) from PostgreSQL usingcurrent_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.
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.