This project involves storing and working with embeddings in PostgreSQL. To enable this functionality, the pgvector extension is required, which allows PostgreSQL to handle vector data types for embedding storage and operations.
Before you can store embeddings in PostgreSQL, you must install the pgvector extension. Follow the steps below to set it up.
- PostgreSQL 12 or later (the guide below is for PostgreSQL 16)
git,make,gcc, andpostgresql-server-dev-16
-
Ensure the required packages are installed: Run the following command to install necessary build tools and PostgreSQL development files:
sudo apt update sudo apt install git make gcc postgresql-server-dev-16 sudo apt search pgvector sudo apt install postgresql-pgvector
-
Enable extension:
CREATE EXTENSION IF NOT EXISTS vector;
-
Create table for embeddings:
CREATE TABLE embeddings ( id SERIAL PRIMARY KEY, text_content TEXT, -- optional, to store associated text or metadata embedding vector(1536) -- size of the vector (e.g., 1536 dimensions for OpenAI models) );