selfhost.directory

The index of self-hostable projects — ranked, categorized and served with live updates.
Own your data and stop giving it to big tech.

GitHub
pgvector logo

Self-host pgvector

v0.8.7

Open-source vector similarity search for PostgreSQL

BetaOpen SourceOther
sudo yum install pgvector_18
Updated3 weeks ago
LanguageC
Setup difficultyModerate
Stars
23 644
Docker
pgvector/pgvector

What is pgvector?

pgvector is an extension for PostgreSQL that adds vector similarity search capabilities. It stores vectors alongside regular data and enables exact and approximate nearest neighbor searches with multiple distance functions including L2 distance, inner product, cosine distance, L1 distance, Hamming distance, and Jaccard distance. The extension provides ACID transactional guarantees, point-in-time recovery via WAL, and JOINs with other data. Installation options include compiling from source on Linux, Mac, and Windows, using Docker images, Homebrew, PGXN, APT, Yum, pkg, APK, conda-forge, or comes preinstalled with Postgres.app. The extension supports multiple vector types: vector for up to 2,000 dimensions, halfvec for up to 4,000 dimensions, bit for up to 64,000 dimensions, and sparsevec for up to 1,000 non-zero elements.

Should you self-host pgvector?

pgvector scores 76/100 on selfhost.directory (how scoring works) and ranks #1 of 8 in Databases & storage. It has 23 644 GitHub stars, +384 in the last 30 days.

There was no stable release in the past 12 months, so check the repository's recent activity before you rely on it.

Setup is moderate: expect some configuration beyond a single command. An official Docker image is available. It is Other-licensed and written mostly in C.

Its closest alternative on selfhost.directory is tdengine (73/100, 25 191 stars). pgvector scores higher overall. See pgvector vs tdengine side by side.

Features

  • ACID Compliance
  • Approximate nearest neighbor search
  • Binary vectors
  • Exact nearest neighbor search
  • Half-precision vectors
  • HNSW indexing
  • Hybrid Search
  • IVFFlat indexing
  • Multiple distance functions
  • Sparse vectors
  • Subvector indexing
  • Vector quantization

pgvector README

pgvector

Open-source vector similarity search for Postgres

Store your vectors with the rest of your data. Supports:

  • exact and approximate nearest neighbor search
  • single-precision, half-precision, binary, and sparse vectors
  • L2 distance, inner product, cosine distance, L1 distance, Hamming distance, and Jaccard distance
  • any language with a Postgres client

Plus ACID compliance, point-in-time recovery, JOINs, and all of the other great features of Postgres

How to install pgvector

Install pgvector with Docker

docker pull pgvector/pgvector:pg18-trixie

FAQ

Do indexes need to fit into memory?

No, but like other index types, you'll likely see better performance if they do. You can get the size of an index with pg_size_pretty. Use half-precision indexing or binary quantization for smaller indexes.

Can I store vectors with more precision?

You can use the double precision[] or numeric[] type to store vectors with more precision.

Can I store vectors with different dimensions in the same column?

You can use vector as the type (instead of vector(n)). However, you can only create indexes on rows with the same number of dimensions using expression and partial indexing.

What if I want to index vectors with more than 2,000 dimensions?

You can use half-precision vectors or half-precision indexing to index up to 4,000 dimensions or binary quantization to index up to 64,000 dimensions. Other options are indexing subvectors or dimensionality reduction.

Is replication supported?

Yes, pgvector uses the write-ahead log (WAL), which allows for replication and point-in-time recovery.

How many vectors can be stored in a single table?

A non-partitioned table has a limit of 32 TB by default in Postgres. A partitioned table can have thousands of partitions of that size.

More in Databases & storage

Rate this project

Click to rate — no account needed.

0 comments

Posting as guest
Loading comments…