Back to Cocoindex

PostgreSQL Source Example (v1) 🗄️

examples/postgres_source/README.md

1.0.31.1 KB
Original Source

PostgreSQL Source Example (v1) 🗄️

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.

Prerequisites

  1. Install dependencies:
sh
pip install -e .
  1. Follow the CocoIndex PostgreSQL setup guide to install and configure PostgreSQL with pgvector extension.

  2. Create source table source_products with sample data:

sh
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.

Run

Build/update the index:

sh
cocoindex update main.py

Query:

sh
python main.py query "wireless headphones"