Key takeaways
- pgvector is an open-source PostgreSQL extension that adds a vector type, distance operators and vector indexes.
- It was created by Andrew Kane and is maintained as an open-source project under the PostgreSQL licence.
- Install it with your package manager or Docker; on Windows, build it with Visual Studio's command-line tools.
- Enable it per database with CREATE EXTENSION vector, then add vector columns and HNSW indexes.
- Estimate memory as about 4 bytes per dimension per vector plus HNSW graph overhead, then measure.
pgvector is an open-source extension for PostgreSQL that adds a vector data type, distance operators and approximate nearest-neighbour indexes, so you can store embeddings next to your relational data and run similarity search with SQL. It is the most common way to add vector search to Postgres. PostgreSQL is a core part of my stack, so this page covers what pgvector is, the pgvector store, who owns it, installing and enabling it including on Windows, using it, HNSW, and estimating memory.
What is pgvector in PostgreSQL?
pgvector is a PostgreSQL extension for storing vectors and querying them by similarity. It adds vector column types, operators for L2 distance, inner product, cosine distance and L1 distance, and IVFFlat and HNSW indexes for fast approximate search.
Because vectors live in normal tables, you get joins, transactions, backups, replication and row-level security, and you can filter by any column in the same query. It also supports half-precision vectors, binary vectors and sparse vectors for different storage and search needs. Most managed Postgres services, including those from major cloud providers, offer pgvector, so you can often enable it without installing anything.
What is the pgvector store?
"PGVector store" usually refers to the vector store integration in frameworks such as LangChain and LlamaIndex that uses PostgreSQL with pgvector as the backend for storing document chunks, embeddings and metadata for retrieval.
Also asked as: what is pgvector store
In LangChain, the PGVector vector store, in the langchain-postgres package, creates tables for collections and embeddings and lets you add documents and run similarity searches with metadata filters through the standard retriever interface. It is convenient for prototypes. For production, many teams design their own tables, indexes and SQL for full control over schema, migrations, filters and hybrid search with Postgres full-text search.
Who owns pgvector?
pgvector was created by Andrew Kane, a developer known for many open-source libraries, and is maintained as an open-source project on GitHub with community contributions. It is released under the PostgreSQL licence, a permissive licence.
No company owns it in a commercial sense; anyone can use, modify and distribute it, including in commercial products. Cloud providers and database companies contribute improvements and package it for their services. When using a managed service, check which pgvector version it offers, because features such as HNSW indexes, half-precision vectors and iterative index scans arrived in specific versions.
How do I install pgvector?
Use your platform's package manager or a ready-made Docker image. On Debian or Ubuntu with the PostgreSQL repository, install the package for your Postgres version; on macOS, use Homebrew; or run the pgvector/pgvector Docker image.
Also asked as: how to install pgvector
Examples:
sudo apt install postgresql-16-pgvector # Debian or Ubuntu, Postgres 16
brew install pgvector # macOS with Homebrew
docker run -e POSTGRES_PASSWORD=dev -p 5432:5432 pgvector/pgvector:pg16
You can also compile from source with make and make install. On managed databases, you usually only need to enable the extension. Match the package to your exact PostgreSQL major version.
How do I install pgvector in PostgreSQL on Windows?
On Windows, build pgvector from source using Visual Studio's C++ build tools: open the x64 Native Tools Command Prompt as administrator, set PGROOT to your PostgreSQL install folder, then run nmake with the Windows makefile and install.
Also asked as: how to install pgvector in postgresql windows
set "PGROOT=C:\Program Files\PostgreSQL\16"
cd %TEMP%
git clone https://github.com/pgvector/pgvector.git
cd pgvector
nmake /F Makefile.win
nmake /F Makefile.win install
Then enable the extension in your database. If building is inconvenient, run PostgreSQL with pgvector in Docker Desktop or WSL, which avoids compiling. Check the repository's README for the current version tag to clone.
How do I enable pgvector in PostgreSQL?
Connect to your database and run CREATE EXTENSION vector;. You need permission to create extensions, and the extension must be installed on the server. Enable it in each database where you need it.
Also asked as: how to enable pgvector in postgresql
Verify with SELECT extversion FROM pg_extension WHERE extname = 'vector';. On managed services, you may need to allow the extension in settings first, depending on the provider. To upgrade after installing a newer version, run ALTER EXTENSION vector UPDATE;. Note the extension's SQL name is vector, not pgvector, which is a common source of "extension does not exist" errors.
How do I use pgvector in PostgreSQL?
Create a table with a vector column of your embedding's dimension, insert embeddings from your model, create an HNSW index, and query with a distance operator ordered by nearest first, with a limit.
Also asked as: how to use pgvector in postgresql
CREATE TABLE chunks (id bigserial PRIMARY KEY, content text, embedding vector(768));
CREATE INDEX ON chunks USING hnsw (embedding vector_cosine_ops);
SELECT id, content FROM chunks ORDER BY embedding <=> $1 LIMIT 5;
The <=> operator is cosine distance, <-> is L2 distance and <#> is negative inner product. Add WHERE clauses for metadata filters, and combine with Postgres full-text search for hybrid retrieval.
Does pgvector support HNSW?
Yes. pgvector added HNSW indexes in version 0.5.0 in 2023, alongside its earlier IVFFlat indexes. HNSW generally gives better speed and recall trade-offs than IVFFlat and does not need a training step, though it builds more slowly and uses more memory.
Tune with m, the number of connections per node, and ef_construction when building, and hnsw.ef_search at query time for higher recall. Build indexes after bulk loading data for speed, and increase maintenance_work_mem so the graph fits in memory during builds. Newer versions support parallel index builds and iterative scans that help when filters remove many results.
Does pgvector use Lucene-based HNSW?
No. pgvector implements HNSW itself, in C, inside PostgreSQL's index access method framework. Lucene, the library behind Elasticsearch and OpenSearch, has its own separate HNSW implementation.
Also asked as: does pgvector use lucene based hnsw
Both follow the same algorithm from the 2016 HNSW paper by Malkov and Yashunin, with multi-layer graphs of nearest neighbours, but implementations differ in storage, concurrency, filtering and tuning parameters. pgvector's index is stored in PostgreSQL pages, uses its buffer cache and benefits from write-ahead logging and replication. So performance comparisons between pgvector and Lucene-based engines depend on configuration and workload, not the algorithm name.
How do I calculate the RAM needed for N vectors of D dimensions with pgvector HNSW?
Start with raw vector size: N times D times 4 bytes for standard vectors, plus a small per-row overhead. The HNSW index stores the vectors again plus graph links, so budget roughly the same again or more for the index, then measure.
Also asked as: how to calculate amount of ram required for serving x n-dimensional vectors with pgvector (hnsw
Example: one million 768-dimension vectors take about 3 GB as raw data, and the HNSW index adds a similar amount or more, depending on m. For fast queries, the index should fit in RAM, so plan for shared buffers and the operating system cache to hold it. Reduce memory with half-precision halfvec, which halves storage, or binary quantisation with re-ranking. Build an index on a sample and check pg_relation_size to extrapolate accurately.






