---
title: "How to Use pgvector for Similarity Search on Heroku Postgres"
description: "Heroku Postgres now supports pgvector on all Standard-tier or higher databases running Postgres 15, adding vector storage and functions for similarity search and machine-learning applications. Older Postgres versions require an upgrade to Postgres 15. The workflow generates embeddings, adds a VECTOR(100) column, and stores values using SQL or Python with psycopg, pgvector-python, and Wikipedia2Vec’s pretrained 100-dimensional model. Queries can rank vectors with Euclidean, cosine, or inner-product distance; the example uses <-> to return five animals nearest to shark, producing crocodile, dolphin, whale, turtle, and alligator. Results depend on the embedding model and corpus, while indexes introduce approximate nearest-neighbor search; pgvector supports IVFFlat and HNSW, with IVFFlat requiring table data for better recall."
---

# How to Use pgvector for Similarity Search on Heroku Postgres

[Heroku](https://yomu.fyi/company/heroku) · Valerie Woolard · Nov 16, 2023

**Type:** Tutorial

## Summary

Heroku Postgres now supports pgvector on all Standard-tier or higher databases running Postgres 15, adding vector storage and functions for similarity search and machine-learning applications. Older Postgres versions require an upgrade to Postgres 15. The workflow generates embeddings, adds a VECTOR(100) column, and stores values using SQL or Python with psycopg, pgvector-python, and Wikipedia2Vec’s pretrained 100-dimensional model. Queries can rank vectors with Euclidean, cosine, or inner-product distance; the example uses <-> to return five animals nearest to shark, producing crocodile, dolphin, whale, turtle, and alligator. Results depend on the embedding model and corpus, while indexes introduce approximate nearest-neighbor search; pgvector supports IVFFlat and HNSW, with IVFFlat requiring table data for better recall.

## Context

Heroku Postgres added pgvector to support vector data associated with large language models and other machine-learning applications. Embeddings are often produced in vector format, enabling similarity searches alongside existing relational data. The feature is available on Standard-tier or higher databases running Postgres 15.

## Approach / What changed

Enable the vector extension with CREATE EXTENSION vector, create a dimensioned vector column, and populate it with embeddings generated by Wikipedia2Vec or another embedding model. The example uses SQL or Python with psycopg and pgvector-python, then queries distance operators for similarity. It also describes IVFFlat and HNSW indexing considerations.

## Takeaways

- The example stores Wikipedia2Vec word embeddings in a VECTOR(100) column and uses Python with psycopg and pgvector-python to insert generated vectors.
- pgvector provides Euclidean distance (<->), cosine distance (<=>), and inner product (<#>) functions; the appropriate choice depends on the data and use case.
- Adding a vector index changes searches from exact to approximate nearest-neighbor search, which can affect results; IVFFlat and HNSW are the supported index types.

**Tags:** [Heroku](https://yomu.fyi/topic/heroku), [pgvector](https://yomu.fyi/topic/pgvector), [Postgres](https://yomu.fyi/topic/postgres), [Python](https://yomu.fyi/topic/python)

- Source: [Heroku](https://www.heroku.com/blog/pgvector-for-similarity-search-on-heroku-postgres)
- Source URL: https://www.heroku.com/blog/pgvector-for-similarity-search-on-heroku-postgres
- Ingested by Yomu: 2026-09-09T20:04:11.406Z

[Read original post](https://www.heroku.com/blog/pgvector-for-similarity-search-on-heroku-postgres)
