<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: bkmalan</title>
    <description>The latest articles on DEV Community by bkmalan (@bkmalan).</description>
    <link>https://dev.to/bkmalan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F692026%2F1105290b-ec00-4f78-89a5-c7687150d2a5.jpeg</url>
      <title>DEV Community: bkmalan</title>
      <link>https://dev.to/bkmalan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bkmalan"/>
    <language>en</language>
    <item>
      <title>How to add pg_embedding extension to PostgreSQL</title>
      <dc:creator>bkmalan</dc:creator>
      <pubDate>Thu, 27 Jul 2023 05:32:07 +0000</pubDate>
      <link>https://dev.to/bkmalan/how-to-add-pgembedding-extension-to-postgresql-2ii6</link>
      <guid>https://dev.to/bkmalan/how-to-add-pgembedding-extension-to-postgresql-2ii6</guid>
      <description>&lt;p&gt;The new &lt;code&gt;pg_embedding&lt;/code&gt; 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.&lt;/p&gt;

&lt;p&gt;Open-source extensions like &lt;code&gt;pgvector&lt;/code&gt; and &lt;code&gt;pg_embedding&lt;/code&gt; 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 &lt;a href="https://neon.tech/blog/pg-embedding-extension-for-vector-search"&gt;here&lt;/a&gt;. The installation process for both extensions remains the same.&lt;/p&gt;

&lt;p&gt;You can also install this on Postgres running on Docker, skip to the section below.&lt;/p&gt;

&lt;p&gt;Let's get started.&lt;/p&gt;

&lt;p&gt;Step 1: Begin by cloning &lt;code&gt;pg_embedding&lt;/code&gt; from its repository and move it to &lt;code&gt;/tmp&lt;/code&gt; directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/neondatabase/pg_embedding.git
mv pg_embedding /tmp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 2: Navigate to the &lt;code&gt;pg_embedding&lt;/code&gt; directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /tmp/pg_embedding
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 3: To ensure smooth compatibility with your PostgreSQL version, install the required dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install postgresql-server-dev-XX
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(Replace XX with your PostgreSQL version. For example if you're using Postgres 15.3 use 15)&lt;/p&gt;

&lt;p&gt;Step 4: Next, build and install the project using make command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;make
sudo make install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 5: Now, let's add the extension using &lt;code&gt;psql&lt;/code&gt;.&lt;br&gt;
   Note: You need login as superuser to be able to add    extensions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo su postgres # Login as super user
psql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 6: Following command creates the extension&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;create extension embedding;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 7: Verify the installation by checking the extensions with the &lt;code&gt;\dx&lt;/code&gt; command and &lt;code&gt;\q&lt;/code&gt; to quit &lt;code&gt;psql&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you'd like to add the extension to Postgres running on Docker, &lt;/p&gt;

&lt;p&gt;Obtain the name or ID of your Postgres container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker ps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you have it, let's dive into the container to do some shell scripting:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker exec -it &amp;lt;NAME | ID&amp;gt; sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Voila! You've gained access to the Docker realm. Execute the same commands used on the mainland to work your magic within Docker.&lt;/p&gt;

&lt;p&gt;But, heed this warning! 🚨 Your Docker installation may be hampered by missing additional packages like git, make, gcc, and g++. To sail smoothly, install them with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install git make gcc g++
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pro Tip: Clone the repo and copy the &lt;code&gt;pg_embedding&lt;/code&gt; directory to docker container and skip git installation using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker cp pg_embedding &amp;lt;CONTAINER_ID&amp;gt;:/tmp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Continue from Step 2 to finish the installation.&lt;/p&gt;

&lt;p&gt;There you have it! 🌟 You've successfully installed the &lt;code&gt;pg_embedding&lt;/code&gt; extension. Happy coding and may your endeavors be magical! 🧚‍♀️&lt;/p&gt;

&lt;p&gt;Credits:&lt;br&gt;
Photo by &lt;a href="https://unsplash.com/@sickle?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Sergey Pesterev&lt;/a&gt; on &lt;a href="https://unsplash.com/images/nature/landscape?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>langchain</category>
      <category>python</category>
      <category>postgres</category>
      <category>linux</category>
    </item>
  </channel>
</rss>
