DEV Community

mehmet akar
mehmet akar

Posted on • Edited on

1

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.

Related:
Free Vector Database
Postgresql Vector Database
Pgvector Tutorial
Vector DB Benchmark
Pinecone vs Pgvector

Billboard image

The fastest way to detect downtimes

Join Vercel, CrowdStrike, and thousands of other teams that trust Checkly to streamline monitoring.

Get started now

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay