examples/postgres_source/README.md
This example demonstrates how to use a PostgreSQL table as a source for CocoIndex v1. It reads structured product data from an existing table, computes derived fields, generates embeddings, and stores results in another PostgreSQL table.
We appreciate a star ⭐ at CocoIndex Github if this is helpful.
pip install -e .
A running Postgres with the pgvector extension. If you don't have one, start a local instance with the compose file in this repo:
docker compose -f ../../dev/postgres.yaml up -d
Create source table source_products with sample data:
psql "postgres://cocoindex:cocoindex@localhost/cocoindex" -f ./prepare_source_data.sql
For simplicity, we use the same database for source and target. You can also set SOURCE_DATABASE_URL to use a separate database.
Build/update the index (one-shot catch-up; the postgres source does not support live mode):
cocoindex update main
Query:
python main.py "wireless headphones"