--- title: 'pgvector vs Pinecone: cost and performance' description: Direct performance comparison between pgvector and Pinecone. author: egor_romanov categories: - engineering tags: - AI - performance - postgres date: '2023-10-10' toc_depth: 3 imgSocial: 2023-10-10-pgvector-vs-pinecone/pgvector-pinecone-og.png imgThumb: 2023-10-10-pgvector-vs-pinecone/pgvector-pinecone-thumb.png --- At Supabase, we believe that a combination of Postgres and pgvector serves as a better alternative to single-purpose databases like Pinecone for AI tasks. This isn't the first time a Postgres-based solution has successfully rivaled specialized databases designed for specific data types. Timescale for time-series data and Greenplum for analytics are just a few examples. We decided to put Postgres vector performance to the test and run a direct comparison between pgvector and Pinecone. ## What is Pinecone? Pinecone is a fully managed cloud Vector Database that is only suitable for storing and searching vector data. It offers straightforward start-up and scalability. It employs a proprietary ANN index and lacks support for exact nearest neighbors search or fine-tuning. The only setting that allows you to adjust the balance between query accuracy and speed is the choice of pod type when creating an index. So, before we dive into their performance, let us first introduce Pinecone's offerings. ### Pinecone has 3 Pod types for indexes An index on Pinecone is made up of pods, which are units of cloud resources (vCPU, RAM, disk) that provide storage and compute for each index. | Type | Capacity / Vectors | QPS | Accuracy | Price per unit per month | | ---- | --------------------------------- | ------- | -------- | ------------------------ | | s1 | 5,000,000 768d (~2,500,000 1536d) | Slowest | 0.98 | $80 | | p1 | 1,000,000 768d (~500,000 1536d) | Medium | 0.99 | $80 | | p2 | 1,100,000 768d (~550,000 1536d) | Fastest | 0.94 | $120 | Pods can be scaled in 2 dimensions: vertically and horizontally: - **vertical scaling** can be used to fit more vectors on a single pod: x1, x2, x4, x8; - **horizontal scaling** increases the number of pods or creates replicas to boost queries per second (QPS). This works linearly for Pinecone: doubling the number of replica pods doubles your QPS. ## Benchmarking methodology We utilized the [ANN Benchmarks](https://github.com/erikbern/ann-benchmarks) methodology, a standard for benchmarking vector databases. Our tests used the [dbpedia dataset](https://huggingface.co/datasets/KShivendu/dbpedia-entities-openai-1M/blob/main/README.md) of 1,000,000 OpenAI embeddings (1536 dimensions) and inner product distance metric for both Pinecone and pgvector. To compare Pinecone and pgvector on equal grounds, we opted for the following setups: - **pgvector**: A single Supabase 2XL instance approximating ~410$/month (8-core ARM CPU and 32 GB RAM). An HNSW index with the following build parameters: `m='36'`, `ef_construction='128'`. - **Pinecone**: Vertically scaled pod to the minimum option that fits the dbpedia dataset into the index on a single pod. We then added replicas to match the budget (slightly exceeding in all cases with ~$480/month). To reduce network latency, we placed our clients in the same cloud provider and region as the database. Experiments were run in a parallel configuration, varying the number of concurrent clients from 5 to 100 to determine the maximum QPS for each setup. ### Measuring accuracy in Pinecone There is no available information on Pinecone's proprietary ANN index. Likewise, they doesn't provide information about query accuracy, nor does it support exact nearest neighbors search (KNN). So to measure Pinecone's accuracy, we had to compare its results with pgvector's exact search (KNN without indexes) for the same queries. This seems to be the only way to measure Pinecone's index accuracy. ## Benchmarking Results ### Pinecone with s1 pod type As the index can fit in a single s1.x1 pod ($80/month), we created five additional replicas. Our Pinecone setup consisted of **six s1 pods** (totaling $480/month). We measured Pinecone's accuracy for the dbpedia dataset using the s1 pod type, achieving a score of 0.98 at the 10 nearest neighbors (accuracy@10). To match the measured .98 accuracy@10 of Pinecone s1 pods, we set `ef_search=32` for pgvector (HNSW) queries, and observed the following results:
## pgvector's hidden cost-saving benefits
There are also a couple of benefits from a developer experience perspective that we often take for granted when using Postgres:
- Postgres offers numerous features applicable to your vectors: [database backups](/docs/guides/platform/backups), row-level security, client libraries support and ORMs for 18 languages, complete ACID compliance, bulk updates and deletes (metadata updates in seconds).
- Having all your data in a sole Postgres instance (or a cluster) reduces roundtrips in production and allows running the entire developer setup locally.
- Implementing additional databases can increase operational complexity and the learning curve.
- Postgres is battle-tested and robust, whereas most specialized vector databases haven't had time to demonstrate their reliability.
## Start using HNSW
All [new Supabase databases](https://database.new/) automatically ship with pgvector v0.5.0 which includes the new HNSW indexes. Try it out today and let us know what you think!
## More pgvector and AI resources
- [pgvector v0.5.0: Faster semantic search with HNSW indexes](https://supabase.com/blog/increase-performance-pgvector-hnsw)
- [Docs pgvector: Embeddings and vector similarity](https://supabase.com/docs/guides/database/extensions/pgvector)
- [Choosing Compute Add-on for AI workloads](https://supabase.com/docs/guides/ai/choosing-compute-addon)
- [pgvector: Fewer dimensions are better](https://supabase.com/blog/fewer-dimensions-are-better-pgvector)
- [Hugging Face is now supported in Supabase](https://supabase.com/blog/hugging-face-supabase)
- [ChatGPT plugins now support Postgres & Supabase](https://supabase.com/blog/chatgpt-plugins-support-postgres)