---
title: "Optimizing vector search performance with pgvector"
description: "pgvector's default sequential scan gives exact, 100%-recall similarity search but slows noticeably past about 50k rows."
url: "https://swe.quest/articles/optimizing-vector-search-performance-with-pgvector-4b331670a6e9890b"
canonical: "https://neon.com/blog/optimizing-vector-search-performance-with-pgvector"
source: "Neon"
published: "2023-06-28"
difficulty: "medium"
kind: "How-to"
reading_minutes: 4
tags: ["vector-search","postgres","performance"]
---

# Optimizing vector search performance with pgvector

A post on [Neon](https://swe.quest/sources/neon.md), published 2023-06-28, 4 min read, How-to. Original: [https://neon.com/blog/optimizing-vector-search-performance-with-pgvector](https://neon.com/blog/optimizing-vector-search-performance-with-pgvector)

## Summary

pgvector's default sequential scan gives exact, 100%-recall similarity search but slows noticeably past about 50k rows. On GIST-960 subsets (10k to 1M rows) on a 4 vCPU/16 GB Neon instance, a 10k-row seq scan took about 36-39 ms, while an ivfflat index cut a sample query to about 6 ms at the cost of approximate recall. Tuning ivfflat's lists and probes trades speed for recall, and recall plateaus while latency keeps rising as probes increase. Suggested starting points are lists = rows/1000 (sqrt(rows) above 1M) and probes = lists/10 (sqrt(lists) above 1M).

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

## Keywords

pgvector, IVFFlat, GIST-960, Neon, PostgreSQL

## Related posts

- [pgvector 0.4.0 performance](https://swe.quest/articles/pgvector-0-4-0-performance-559fc540f926a562.md): Supabase · 2023-07-13 · Medium · 8 min read · Vector search, PostgreSQL, Performance engineering, Inference & serving
  With tuned settings, pgvector 0.4.0's IVFFlat index handles 1M OpenAI embeddings (1536 dimensions, dbpedia dataset) at about 1800 QPS with 0.91 accuracy@10 on a 64-core, 256 GB instance, or about 670 QPS at 0.98 accuracy.
- [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.
- [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.
- [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.

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)
