Logo Ng Ting Sheng

pgvector: Vector Search the Postgres Way

May 15, 2025 - 4 minute read

vector_database Vector databases have been pivotal in giving large language models (LLMs) the ability to retrieve proprietary knowledge, which helps reduce hallucinations.

Many purpose-built vector databases like Pinecone, Weaviate, and Qdrant are designed for speed and scale. However, if you’re already using PostgreSQL, pgvector is a strong contender for your first vector database.

Why pgvector?

pgvector is an open-source extension for PostgreSQL. It introduces a new vector data type and lets you perform vector similarity searches directly within your existing Postgres database. When I was exploring vector database options, my stack was already heavily invested in PostgreSQL. That’s when pgvector became a game-changer. I could store vector embeddings right alongside my relational data, all in one place without having to introduce a new database engine into my architecture. Here’s why pgvector is so attractive:

  • Simple, Low Friction & Familiar

    This is arguably the biggest advantage. If you already know PostgreSQL, you’re 90% there. There’s no new system to learn, deploy, manage, or secure. You can keep using your existing tools, backup procedures, monitoring stack, and client libraries. For deployments and infrastructure, there is also very little overhead to start with. This makes it incredibly easy for teams already in the Postgres ecosystem to unlock vectorization.

  • Unified Data Stack

    By storing structured and vector data together, you simplify your architecture. You can run complex SQL queries that combine vector similarity and relational filters in a single operation, without the need for application-level joins or multi-database coordination.

  • Cost Efficiency

    Since pgvector is just an extension on top of an existing database, there is no additional infrastructure cost or new vendor approval required. You might not need complicated accounting approval to provision new infrastructure, which is great!

  • Rich Ecosystem

    You get to leverage the entire PostgreSQL ecosystem, including its powerful indexing, querying capabilities, and countless other extensions.

Limitations of pgvector

While pgvector offers many benefits, it’s important to understand where it falls short, especially compared to purpose-built vector databases.

  • Latency and throughput

    For applications with billions of vectors and high query volume, dedicated vector databases can deliver lower latency and higher throughput. Their architectures are optimized for this specific workload, whereas Postgres remains a general-purpose database.

  • Scaling Challenges

    Scaling pgvector typically relies on traditional PostgreSQL approaches like vertical scaling, read replicas, or manual sharding. While effective, they come with added operational complexity. In contrast, many dedicated vector databases are distributed by design and handle horizontal scaling much more seamlessly.

  • Indexing and Memory Usage

    While pgvector supports popular and effective indexing methods like HNSW (Hierarchical Navigable Small World), its indexing can be memory-intensive. For large datasets, this can lead to significant RAM usage to maintain low-latency performance. Dedicated vector databases often employ more efficient memory management and quantization techniques, reducing the hardware requirements while maintaining search quality.

Using pgvector on AWS RDS

If you use cloud services like AWS, you likely use RDS as well. One of the best things about pgvector is that it’s a supported extension on Amazon RDS for PostgreSQL. Just run:

1
CREATE EXTENSION vector;

That’s it. You can now add vector columns to your tables and start building AI applications on top of your managed Postgres instance.

The Trade-off: Simplicity vs. Specialization

Choosing pgvector is often a decision rooted in its primary advantage: simplicity and integration. For teams already using PostgreSQL, pgvector is an extension that can be added to their existing database, avoiding the need to set up, manage, and synchronize data with a separate, specialized system.

However, for applications where vector search is the core, performance-critical component and the scale is expected to be massive, the specialized optimizations of a dedicated vector database can provide a significant advantage that outweighs the convenience of an integrated solution.

So, depending on what stage you’re in, pgvector is a strong option to start with, especially if you’re new to vector databases. Its scalability relies mainly on vertical scaling — increasing CPU and RAM (which is critical for HNSW indexing). This means it can scale effectively up to a certain point, so you have to understand the scale you’re expecting. If you’re building your own SaaS as a solo developer, creating a PoC, or developing an internal tool, chances are pgvector is more than enough.