---
title: "20x faster than pgvector: introducing pg_embedding extension for vector search in Postgres and LangChain"
description: "pg_embedding brought HNSW graph-based approximate nearest neighbor indexing to Postgres."
url: "https://swe.quest/articles/20x-faster-than-pgvector-introducing-pg-embedding-extension-for-vector-search-058737fc9388f495"
canonical: "https://neon.com/blog/pg-embedding-extension-for-vector-search"
source: "Neon"
published: "2023-07-11"
difficulty: "medium"
kind: "Announcement"
reading_minutes: 7
tags: ["vector-search","postgres","performance"]
---

# 20x faster than pgvector: introducing pg\_embedding extension for vector search in Postgres and LangChain

A post on [Neon](https://swe.quest/sources/neon.md), published 2023-07-11, 7 min read, Announcement. Original: [https://neon.com/blog/pg-embedding-extension-for-vector-search](https://neon.com/blog/pg-embedding-extension-for-vector-search)

## Summary

pg\_embedding brought HNSW graph-based approximate nearest neighbor indexing to Postgres. On the GIST-960 dataset (1M 960-dim vectors, k=100, 4 vCPU/16 GB), it ran 5–30x faster than pgvector's IVFFlat at equal recall. IVFFlat needs more probes to raise recall and drifts toward a sequential scan, while HNSW's layered graph gives roughly logarithmic search. HNSW trades higher memory use, slower index builds (driven by efConstruction) and L2-only distance for that speed. Neon has since deprecated pg\_embedding in favor of pgvector, which now supports HNSW natively.

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)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)

## 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))
- approximate nearest neighbor search ([easy posts on Search](https://swe.quest/tags/search.md?difficulty=easy))

## Keywords

pg\_embedding, pgvector, HNSW, IVFFlat, LangChain, Neon, GIST-960

## Related posts

- [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.
- [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.
- [On-disk HNSW index for Postgres with pg\_embedding](https://swe.quest/articles/on-disk-hnsw-index-for-postgres-with-pg-embedding-aadc4bd81ebf65c4.md): Neon · 2023-08-03 · Medium · 5 min read · Vector search, PostgreSQL
  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.
- [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;\`.
- [What's new in pgvector v0.7.0](https://swe.quest/articles/what-s-new-in-pgvector-v0-7-0-faa9e83678b64f22.md): Supabase · 2024-05-02 · Medium · 5 min read · Vector search, PostgreSQL, Performance engineering
  pgvector 0.7.0 adds float16 (halfvec), sparse and bit vector types to exploit redundancy in embeddings and cut memory and storage.

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)
