How to add pg_embedding extension to PostgreSQL

how-to-add-pg-embedding-extension-to-postgresql

The new pg_embedding extension was recently released, bringing exciting advancements by boosting graph-based approximate nearest neighbor search speed by 20x with 99% accuracy for your Postgres databases.

Open-source extensions like pgvector and pg_embedding facilitate vector similarity search within Postgres, making it a robust choice for storing vectors and executing similarity searches. However, their indexing methods vary, so it’s essential to explore their differences and choose the most suitable one for your needs more on that here. The installation process for both extensions remains the same.

You can also install this on Postgres running on Docker, skip to the section below.

Let’s get started.

Step 1: Begin by cloning pg_embedding from its repository and move it to /tmp directory:

git clone https://github.com/neondatabase/pg_embedding.git
mv pg_embedding /tmp

Step 2: Navigate to the pg_embedding directory:

cd /tmp/pg_embedding

Step 3: To ensure smooth compatibility with your PostgreSQL version, install the required dependencies:

sudo apt install postgresql-server-dev-XX

(Replace XX with your PostgreSQL version. For example if you’re using Postgres 15.3 use 15)

Step 4: Next, build and install the project using make command:

make
sudo make install

Step 5: Now, let’s add the extension using psql.
Note: You need login as superuser to be able to add extensions.

sudo su postgres # Login as super user
psql

Step 6: Following command creates the extension

create extension embedding;

Step 7: Verify the installation by checking the extensions with the dx command and q to quit psql.

If you’d like to add the extension to Postgres running on Docker,

Obtain the name or ID of your Postgres container:

docker ps

Once you have it, let’s dive into the container to do some shell scripting:

docker exec -it  sh

Voila! You’ve gained access to the Docker realm. Execute the same commands used on the mainland to work your magic within Docker.

But, heed this warning! 🚨 Your Docker installation may be hampered by additional packages like git make, gcc, and g++. To sail smoothly, install them with:

sudo apt-get install git make gcc g++

Pro Tip: Clone the repo and copy the pg_embedding directory to docker container and skip git installation using:

docker cp pg_embedding :/tmp

Continue from Step 2 to finish the installation.

There you have it! 🌟 You’ve successfully installed the pg_embedding extension. Happy coding and may your endeavors be magical! 🧚‍♀️

Credits:
Photo by Sergey Pesterev on Unsplash

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
how-to-code-a-simple-number-guessing-game-in-python

How To Code a Simple Number Guessing Game in Python

Next Post
“top-frontend-interview-questions-:-(part-1)-—-boost-your-knowledge-and-ace-your-next-job-interview!”

“Top Frontend Interview Questions : (Part 1) — Boost Your Knowledge and Ace Your Next Job Interview!”

Related Posts