09.05 · Walkthrough
pgvector in Postgres
Store embeddings in Postgres with pgvector and execute vector similarity queries with metadata constraints.
No video curated for this lesson yet
This lesson is written, ordered and part of the path - the video slot is the only thing still open. We are working through Everything Data lesson by lesson; 55 of 85 have their video so far.
The written notes below cover this idea in full - you lose nothing by reading instead of watching.
pgvector lets Postgres hold embedding vectors beside ordinary application records, so semantic retrieval can use SQL filters for tenancy, permissions, dates, language and document type. It is a practical option when RAG retrieval needs both nearest-neighbour search and relational metadata constraints without adding a separate vector service.
What this lesson answers
- how to store embeddings in postgres with pgvector
- pgvector similarity search with metadata filters
- when should I use pgvector instead of vector database
Notes
pgvector is a Postgres extension that adds a vector data type and similarity search operators, allowing you to store embeddings directly alongside the rest of your application data. Instead of running a separate vector database for every retrieval use case, you can keep document chunks, IDs, timestamps, permissions, source metadata, and embedding vectors in the same relational database. This is especially useful when your retrieval logic depends not only on semantic similarity, but also on structured filters such as tenant_id, document_type, language, created_at, or access control rules.
A…
Common questions
- What does pgvector add to Postgres?
- pgvector adds a vector column type and operators for comparing embeddings by distance or similarity. That means embeddings can live in the same tables as chunk text, identifiers, timestamps and metadata. Queries can then rank rows by semantic closeness while still using normal SQL predicates for application constraints.
- How do metadata filters work with vector search in Postgres?
- Metadata filters are just SQL conditions applied alongside the vector ordering. A query can restrict rows by tenant, access rules, document type, language or freshness, then sort the remaining candidates by distance from the query embedding. This keeps retrieval aligned with the same rules your application already stores in Postgres.
- Does pgvector remove the need for a separate vector database?
- For many RAG and application search cases, yes. If your retrieval depends heavily on relational metadata and your data already lives in Postgres, pgvector can simplify the architecture. A specialised vector database may still make sense when vector search scale, distribution or operational requirements exceed what your Postgres setup can handle.
Short definition: what is pgvector in Postgres?