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/table to create an embedding job, GET /api/v1/search to query). The server watches the source table, generates embeddings, and keeps them up‑to‑date.
  • Postgres‑extension mode: install the vectorize extension inside the database and call SQL functions such as vectorize.table() and vectorize.search(). This requires filesystem access on the DB host.

Key capabilities

  • Automatic transformation of specified text columns into embeddings.
  • Continuous background updates via pgmq workers.
  • 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 pgvector installed.

Typical workflow (HTTP mode)

  1. Start services – docker compose up -d spins up Postgres, the embedding server, and the management API.
  2. Load data – optional psql … -f server/sql/example.sql creates a sample my_products table.
  3. Create a job – POST /api/v1/table with JSON describing the source table, columns, primary key, timestamp column, and the Sentence‑Transformers model to use.
  4. Search – GET /api/v1/search with job_name, a natural‑language query, and a limit. 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 pgvector needs 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


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