ChuckHend/pg_vectorize
Full-text and semantic search on any Postgres
pg_vectorize – Vector search & RAG on PostgreSQL
What it is – A two‑mode system that lets you store and query text embeddings directly in a PostgreSQL database. It builds on the open‑source pgvector extension for similarity search and pgmq for background job orchestration, and uses Hugging Face’s Sentence‑Transformers models to turn text into vectors.
How it works
- HTTP‑server mode (recommended for managed databases): a standalone service connects to your Postgres instance and exposes a REST API (
POST /api/v1/tableto create an embedding job,GET /api/v1/searchto query). The server watches the source table, generates embeddings, and keeps them up‑to‑date. - Postgres‑extension mode: install the
vectorizeextension inside the database and call SQL functions such asvectorize.table()andvectorize.search(). This requires filesystem access on the DB host.
Key capabilities
- Automatic transformation of specified text columns into embeddings.
- Continuous background updates via
pgmqworkers. - Hybrid search that combines vector similarity, full‑text ranking (
fts_rank), and reciprocal‑rank‑fusion (rrf_score). - Simple REST endpoints for creating jobs and performing queries.
- Works with any PostgreSQL 13‑18 server that has
pgvectorinstalled.
Typical workflow (HTTP mode)
- Start services –
docker compose up -dspins up Postgres, the embedding server, and the management API. - Load data – optional
psql … -f server/sql/example.sqlcreates a samplemy_productstable. - Create a job –
POST /api/v1/tablewith JSON describing the source table, columns, primary key, timestamp column, and the Sentence‑Transformers model to use. - Search –
GET /api/v1/searchwithjob_name, a natural‑language query, and alimit. The response includes the original row fields plus ranking scores and the similarity value.
When to choose which mode
- HTTP server – you are on a managed Postgres service (RDS, Cloud SQL, etc.) or cannot install extensions. Only
pgvectorneeds to be present. - Extension – you control the Postgres host and prefer a pure‑SQL interface without a separate service.
Getting started
# 1. Launch everything locally
docker compose up -d
# 2. (Optional) Load example data
psql postgres://postgres:postgres@localhost:5432/postgres -f server/sql/example.sql
# 3. Create an embedding job
curl -X POST http://localhost:8080/api/v1/table \
-H "Content-Type: application/json" \
-d '{
"job_name": "my_job",
"src_table": "my_products",
"src_schema": "public",
"src_columns": ["product_name", "description"],
"primary_key": "product_id",
"update_time_col": "updated_at",
"model": "sentence-transformers/all-MiniLM-L6-v2"
}'
# 4. Query
curl -G "http://localhost:8080/api/v1/search" \
--data-urlencode "job_name=my_job" \
--data-urlencode "query=camping backpack" \
--data-urlencode "limit=1" | jq .
Where to learn more
- Full API docs: https://chuckhend.github.io/pg_vectorize/
- Extension usage:
./extension/README.md - Server deployment notes:
./server/README.md - Contribution guidelines:
CONTRIBUTING.md
pg_vectorize lets you add semantic, full‑text, and hybrid search to any PostgreSQL database, making it straightforward to build retrieval‑augmented generation (RAG) pipelines or custom search engines without provisioning a separate vector database.
Related
- Project
- Project
- Project
- Project
- Project