---
title: "On-disk HNSW index for Postgres with pg_embedding"
description: "pg_embedding's new version builds its HNSW vector index on disk rather than in memory and adds cosine, Manhattan and Euclidean (L2) distance support."
url: "https://swe.quest/articles/on-disk-hnsw-index-for-postgres-with-pg-embedding-aadc4bd81ebf65c4"
canonical: "https://neon.com/blog/pg_embedding-on-disk-hnsw-index"
source: "Neon"
published: "2023-08-03"
difficulty: "medium"
kind: "Release"
reading_minutes: 5
tags: ["vector-search","postgres"]
---

# On-disk HNSW index for Postgres with pg\_embedding

A post on [Neon](https://swe.quest/sources/neon.md), published 2023-08-03, 5 min read, Release. Original: [https://neon.com/blog/pg\_embedding-on-disk-hnsw-index](https://neon.com/blog/pg_embedding-on-disk-hnsw-index)

## Summary

pg\_embedding's new version builds its HNSW vector index on disk rather than in memory and adds cosine, Manhattan and Euclidean (L2) distance support. Benchmarks on an 8 vCPU / 32 GB machine show the in-memory index is roughly 2x faster, but persisting the index lets it work with Neon's autoscaling, scale-to-zero and read replicas for read-heavy similarity search. The post walks through enabling the extension, storing embeddings as real\[\] and tuning the index parameters dims, m, efConstruction and efSearch, where efSearch should be at least the query's LIMIT k. Neon has since discontinued pg\_embedding and recommends pgvector instead.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Vector search](https://swe.quest/tags/vector-search.md) (Data & databases)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)

## Prerequisites

- PostgreSQL extensions ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- vector embeddings ([easy posts on RAG & retrieval](https://swe.quest/tags/rag.md?difficulty=easy))

## Keywords

pg\_embedding, HNSW, Neon, pgvector, IVFFlat, LangChain

## Related posts

- [20x faster than pgvector: introducing pg\_embedding extension for vector search in Postgres and LangChain](https://swe.quest/articles/20x-faster-than-pgvector-introducing-pg-embedding-extension-for-vector-search-058737fc9388f495.md): Neon · 2023-07-11 · Medium · 7 min read · Vector search, PostgreSQL, Performance engineering
  pg\_embedding brought HNSW graph-based approximate nearest neighbor indexing to Postgres.
- [pgvector v0.5.0: Faster semantic search with HNSW indexes](https://swe.quest/articles/pgvector-v0-5-0-faster-semantic-search-with-hnsw-indexes-d1e5c38ac44f551e.md): Supabase · 2023-09-06 · Medium · 6 min read · Vector search, PostgreSQL, Performance engineering, Algorithms
  pgvector v0.5.0 adds HNSW indexes, which combine skip-list-style layering with navigable small world proximity graphs to do approximate nearest-neighbor search over embeddings.
- [Understanding vector search and HNSW index with pgvector](https://swe.quest/articles/understanding-vector-search-and-hnsw-index-with-pgvector-db3498f2e1e5486e.md): Neon · 2023-09-20 · Medium · 10 min read · Vector search, PostgreSQL, LLMs
  pgvector 0.5.0 adds an HNSW (Hierarchical Navigable Small Worlds) index for approximate nearest neighbor search in Postgres, replacing O(N) sequential exact scans with a multi-layer graph traversal that trades a little accuracy for much faster queries.
- [How to Use pgvector for Similarity Search on Heroku Postgres](https://swe.quest/articles/how-to-use-pgvector-for-similarity-search-on-heroku-postgres-c4879269328732cd.md): Heroku Engineering · 2023-11-16 · Medium · 5 min read · Vector search, PostgreSQL, Python
  Heroku Postgres now supports the pgvector extension on Standard-tier and higher databases running Postgres 15, enabled with \`CREATE EXTENSION vector;\`.
- [pgvector: 30x Faster Index Build for your Vector Embeddings](https://swe.quest/articles/pgvector-30x-faster-index-build-for-your-vector-embeddings-cd6dabfa49eb13de.md): Neon · 2024-02-07 · Medium · 6 min read · Vector search, PostgreSQL, Performance engineering
  pgvector 0.6.0 adds parallel builds for HNSW indexes, cutting build time by up to 30x in benchmarks on 10M 1,536-dimension vectors using a 64 vCPU, 512GB instance.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
