liveBook · Manning

Pgvector

As explained in Just Use Postgres!

pgvector is a PostgreSQL extension that adds vector data types and similarity search capabilities.

pgvector is a PostgreSQL extension that adds vector storage, similarity-search operators, and specialized indexes. It turns PostgreSQL into a vector database for recommendation services, semantic search, clustering, and retrieval-augmented generation. section 8.0 section 8.2

A practical pgvector workflow includes:

  • Start PostgreSQL with a pgvector-enabled image, such as pgvector/pgvector:0.8.0-pg17. section 8.2
  • Enable the extension with CREATE EXTENSION vector; after connecting to PostgreSQL. section 8.2
  • Store embeddings and compare them with cosine distance (<=>), Euclidean distance (<->), or inner product (<#>). section 8.4
  • Optimize searches with IVFFlat or HNSW indexes, balancing search performance, recall, and index size. section 8.7

Enable pgvector in Docker and PostgreSQL

Create a persistent volume and start the database: `docker volume create postgres-pgvector-volume` followed by `docker run --name postgres-pgvector -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password -p 5432:5432 -v postgres-pgvector-volume:/var/lib/postgresql/data -d pgvector/pgvector:0.8.0-pg17`. Connect with `docker exec -it postgres-pgvector psql -U postgres`, then run `CREATE EXTENSION vector;`. Querying available extensions afterward shows vector version 0.8.0 installed. section 8.2

Figure 8.6 Performing vector similarity search with Postgres
A diagram of a computer application

AI-generated content may be incorrect.

Use the workflow diagram to follow embedding generation, PostgreSQL storage, vector comparison, and recommendation results. section 8.4

How Just Use Postgres! covers it

How deep it goes
Explains setup, distance operators, and index choices, but stops short of detailed index configuration or deployment administration.
Examples
Uses a movie recommendation service, Docker commands, extension SQL, cosine distance, and Star Wars and Jurassic Park descriptions.
What it assumes
Builds on PostgreSQL and embedding models while introducing vector storage, distance operators, and similarity search.
What you can do after
Operate/configure PostgreSQL with pgvector, store embeddings, run similarity searches, and choose HNSW or IVFFlat indexes.
How it connects
Connects PostgreSQL with vector embeddings, embedding models, semantic search, RAG, HNSW, and IVFFlat.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Just Use Postgres!. The section links point to the parts of the book it draws on.