DEV Community

mehmet akar
mehmet akar

Posted on

Install pgvector on Windows

Install pgvector on windows is the most asked issue by pgvector geeks.

pgvector is a PostgreSQL extension that enables vector similarity search capabilities within PostgreSQL databases. While pgvector is widely used in AI and machine learning applications, installing it on Windows requires careful steps. This guide will walk you through the process.

Prerequisites

Before you begin, ensure the following:

  1. PostgreSQL Installed: Download and install PostgreSQL for Windows from the official site.
  2. Git Installed: If not already installed, download Git for Windows from Git.
  3. Build Tools: Install the necessary build tools:
    • Visual Studio with C++ build tools.
    • Add make and other necessary tools to your PATH.

Step 1: Download pgvector Source Code

  1. Clone the pgvector repository:
   git clone https://github.com/pgvector/pgvector.git
Enter fullscreen mode Exit fullscreen mode
  1. Navigate to the pgvector directory:
   cd pgvector
Enter fullscreen mode Exit fullscreen mode

Step 2: Build the Extension

  1. Ensure pg_config is in your PATH. You can locate pg_config in the PostgreSQL installation directory (e.g., C:\Program Files\PostgreSQL\15\bin\pg_config.exe).
  2. Run the following commands in your terminal:
   make
   make install
Enter fullscreen mode Exit fullscreen mode

This will build and install the pgvector extension for your PostgreSQL instance.

Step 3: Enable pgvector in PostgreSQL

  1. Open the PostgreSQL configuration file (e.g., postgresql.conf):
   C:\Program Files\PostgreSQL\15\data\postgresql.conf
Enter fullscreen mode Exit fullscreen mode
  1. Add or uncomment the following line to allow extensions:
   shared_preload_libraries = 'pgvector'
Enter fullscreen mode Exit fullscreen mode
  1. Restart the PostgreSQL service to apply the changes. You can do this using the Services app in Windows or the following command in PowerShell:
   net stop postgresql-x64-15
   net start postgresql-x64-15
Enter fullscreen mode Exit fullscreen mode

Step 4: Create the Extension in PostgreSQL

  1. Open psql, the PostgreSQL command-line tool:
   psql -U postgres
Enter fullscreen mode Exit fullscreen mode
  1. Create the extension:
   CREATE EXTENSION vector;
Enter fullscreen mode Exit fullscreen mode

This will activate pgvector in your PostgreSQL database.

Step 5: Verify Installation

  1. Run the following SQL command to confirm:
   SELECT * FROM pg_available_extensions WHERE name = 'vector';
Enter fullscreen mode Exit fullscreen mode

If the extension is available, you will see it listed with its version and description.

Step 6: Test Vector Functionality

  1. Create a sample table with a vector column:
   CREATE TABLE items (id SERIAL PRIMARY KEY, embedding VECTOR(3));
Enter fullscreen mode Exit fullscreen mode
  1. Insert a sample vector:
   INSERT INTO items (embedding) VALUES ('[1, 2, 3]');
Enter fullscreen mode Exit fullscreen mode
  1. Query the vector data:
   SELECT * FROM items;
Enter fullscreen mode Exit fullscreen mode

Install pgvector on windows Troubleshooting

  • Error: pg_config not found: Ensure the PostgreSQL bin directory is added to your PATH.
  • Build Errors: Verify that Visual Studio is installed with the necessary C++ tools.
  • Permission Issues: Run the terminal or command prompt as an administrator.

Install pgvector on windows: Result

You have successfully installed pgvector on Windows and enabled vector similarity search within PostgreSQL. This setup allows you to leverage powerful AI and machine learning capabilities directly in your database. For further customization and usage, refer to the pgvector GitHub repository.

Top comments (0)