pg_summarize
pg_summarize
pg_summarize : Text Summarization using LLMs. Built using pgrx
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 1860 | pg_summarize
|
pg_summarize
|
0.0.1 |
RAG
|
PostgreSQL
|
Rust
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d--
|
No
|
Yes
|
No
|
Yes
|
no
|
no
|
| Relationships | |
|---|---|
| See Also | vectorize
pg_tiktoken
pg4ml
pgml
vector
vchord
vectorscale
pg_net
|
PG18 fix by https://github.com/Vonng/pg_summarize
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY
|
0.0.1 |
18
17
16
15
14
|
pg_summarize |
- |
| RPM | PIGSTY
|
0.0.1 |
18
17
16
15
14
|
pg_summarize_$v |
- |
| DEB | PIGSTY
|
0.0.1 |
18
17
16
15
14
|
postgresql-$v-pg-summarize |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
el8.aarch64
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
el9.x86_64
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
el9.aarch64
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
el10.x86_64
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
el10.aarch64
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
d12.x86_64
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
PIGSTY 0.0.1
|
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
|
Source
pig build pkg pg_summarize; # build rpm/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall this extension with pig:
pig install pg_summarize; # install via package name, for the active PG version
pig install pg_summarize -v 18; # install for PG 18
pig install pg_summarize -v 17; # install for PG 17
pig install pg_summarize -v 16; # install for PG 16
pig install pg_summarize -v 15; # install for PG 15
pig install pg_summarize -v 14; # install for PG 14Create this extension with:
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_summarizeConfiguration
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.
Last updated on