Skip to main content

pgvector

pgvector adds vector similarity search to PostgreSQL. With it, Bifrost keeps its vectors in a PostgreSQL database, so a deployment that already runs PostgreSQL needs no separate vector database.

Key Features

  • Runs on PostgreSQL: the same database as the config or logs store, or a separate one
  • HNSW indexes: approximate nearest-neighbour search, with filters on stored properties
  • Shared across replicas: every Bifrost replica reads and writes the same tables
  • Own connection pool: pgvector connects with its own settings and pool, like the other vector stores

Requirements

  • PostgreSQL with the pgvector extension, version 0.8.0 or later. 0.8.0 is the first release with iterative index scans, which a filtered search needs to return a full set of results.
  • At startup Bifrost runs CREATE EXTENSION IF NOT EXISTS vector when its database user is allowed to. If it is not, Bifrost refuses to start and prints the command a database administrator has to run.
  • Bifrost does not upgrade an installed extension. An older version makes it refuse to start with the ALTER EXTENSION vector UPDATE; command to run.
  • The extension’s schema must be on the database user’s search_path. If it is not, the startup error names the schema and gives an ALTER ROLE ... SET search_path command that keeps the current entries.

Setup & Installation

Local PostgreSQL:
Managed PostgreSQL (Amazon RDS, Cloud SQL, Azure Database for PostgreSQL, Supabase, and others): the extension is available but has to be created in the database, and older engine versions offer a pgvector older than 0.8.0. Check what the database offers before enabling it:
default_version must be 0.8.0 or later; if it is not, upgrade the engine’s minor version. If Bifrost’s user may not create extensions, have an administrator run CREATE EXTENSION vector; in the database first.

Configuration Options

The store owns its connection pool; store.Close(ctx, "") closes it.

Configuration Reference

The config block takes the same connection settings as a PostgreSQL config or logs store, without the logs store’s materialized-view and migration settings.

How Vectors Are Stored

  • One table per namespace. pgvector indexes only fixed-dimension columns, so each namespace gets its own table, named from a hash of the namespace and its dimension. The vector_store_namespaces table maps namespaces to their tables.
  • Indexing by dimension. Up to 2,000 dimensions a namespace gets an HNSW index on the vector column. From 2,001 to 4,000 it gets an HNSW index over a halfvec expression, and results are re-ranked at full precision. Above 4,000, up to the 16,000 maximum, searches are exact.
  • Properties are one jsonb column with a GIN index, which serves equality and contains filters. Integer properties declared when the namespace is created also get a btree index, which serves range filters.
  • Entries without a vector are allowed, so caches that store metadata-only entries work as they do on Redis.

Production Considerations

  • Connections. pgvector opens its own pool, in addition to the config and logs stores’ pools. A pod’s connection ceiling is the sum of their max_open_conns, which matters on a small managed instance.
  • Shared load. On the same database as the logs store, vector searches and writes share its CPU, memory, and I/O with request logging.
  • Multiple replicas. Replicas coordinate namespace creation and deletion through PostgreSQL advisory locks, so they can start together against an empty database.
  • Session settings. pgvector sets the settings each search needs, such as hnsw.iterative_scan, on the transaction, and pins READ COMMITTED where it depends on it, so it does not rely on the database user’s defaults.
For Kubernetes deployments, see Helm storage. The chart’s bundled PostgreSQL image does not include pgvector by default.
For the VectorStore interface API and usage examples, see Vector Store Architecture. For semantic caching setup, see Semantic Caching.