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

状态模式深度指南:构建可动态切换行为的艺术

状态模式深度指南:构建可动态切换行为的艺术 概述 状态模式(State Pattern)是一种行为型设计模式,它允许对象在内部状态改变时改变其行为。看起来对象似乎修改了其类。这种模式是解决复杂状态转换逻辑的利器,特别适合用于工作流引擎、游戏开发、订单处理系统等场景。 核心概念 状态模式的核心思想是:将每个状态封装为独立的类,对象的行为取决于其当前状态,而状态之间的转换由状态类自己管理。 关键角色 Context(上下文):维护当前状态的实例,负责将请求委托给状态对象处理 State(抽象状态):定义所有具体状态的共同接口 ConcreteState(具体状态):实现各个具体状态的行为,并负责状态转换 为什么需要状态模式? 传统方式的困境 想象一个订单系统,订单有多种状态:待支付、待发货、已发货、已完成、已取消。每个状态下可以执行不同的操作。 // 传统的if-else方式 class Order {…
Read More