How to Set Up pgvector on Windows: Store and Query Vector Embeddings in PostgreSQL
A step-by-step practical guide to installing the pgvector extension on Windows, setting up PostgreSQL for vector embeddings, and enabling AI-powered search and retrieval.
How to Set Up pgvector on Windows: Store and Query Vector Embeddings in PostgreSQL
The surge in AI applications—especially those involving semantic search and embeddings—has made vector databases crucial for developers. The open-source pgvector extension brings vector search capabilities directly to PostgreSQL, making it a go-to solution for projects on a budget or those leveraging existing Postgres infrastructure. In this post, I’ll walk you through setting up pgvector on Windows, getting your database ready for vector data, and running your first queries. All links and resources are included for each step!
Step 1: Install Microsoft Visual Studio with C++ Build Tools
For pgvector to work on Windows, we need a C++ build environment:
Download Visual Studio: https://visualstudio.microsoft.com/downloads/
Choose the Community edition (free for individuals).
During installation, select Desktop development with C++ for the compilers and build tools.
More about C++ tools for Windows: Microsoft Docs
Step 2: Install PostgreSQL (Recommended: Version 15.13)
pgvector is best supported on PostgreSQL 15.13 for Windows:
Official Postgres download: https://www.postgresql.org/download/windows/
Direct Windows installers: https://www.enterprisedb.com/downloads/postgres-postgresql-downloads
During setup, set a superuser password and remember it for later.
Step 3: Download and Compile pgvector from Source
Visit the pgvector repo: https://github.com/pgvector/pgvector
Open x64 Native Tools Command Prompt for VS 2022 as administrator.
Set the environment variable for your PostgreSQL installation:
set PGROOT="C:\Program Files\PostgreSQL\15"Download and compile pgvector:
git clone https://github.com/pgvector/pgvector.git
cd pgvector
nmake /f Makefile.win
nmake /f Makefile.win installStep 4: Enable the Vector Extension in PostgreSQL
Launch pgAdmin (download here) or use the psql shell.
Connect to your Postgres 15 database.
Run:
CREATE EXTENSION vector;Step 5: Create a Table With Vector Column
Let’s make a simple table to store vectors!
Reference: pgvector - Usage
CREATE TABLE items ( id serial PRIMARY KEY, embedding vector(3) -- 3 is the vector dimension in this example );Step 6: Insert and Query Vector Data
Insert a sample vector:
INSERT INTO items (embedding) VALUES ('[1,2,3]');Query the data:
SELECT * FROM items;With these steps, you’re set to harness the power of vector search in your AI projects, all within PostgreSQL running on Windows. If you found this walkthrough helpful or have troubleshooting tips, let me know in the comments below!

