{"post":{"slug":"pgvector-explained-2026","title":"pgvector Explained in 2026: Vector Search in Postgres","excerpt":"pgvector adds a vector type and nearest-neighbor search to Postgres, so RAG and recommendation embeddings live next to your relational data, not apart from it.","category":"code","date":"August 7, 2026","author":"ByteLedger Team","content":"<span class=\"dropcap\">p</span>gvector adds a vector data type and nearest-neighbor search operators directly to Postgres, so embeddings for search, recommendations, and RAG live next to the rest of your relational data instead of in a separate database. You get a `vector` column, distance operators, `<->` for Euclidean, `<=>` for cosine, `<#>` for inner product, and an index type, HNSW or IVFFlat, that makes similarity search fast at scale. For most teams already running Postgres, it removes an entire category of infrastructure, a dedicated vector database, without giving up much search quality. It shipped as a Postgres extension in 2021 and has since become one of the most widely deployed pieces of AI infrastructure, largely because it requires no new operational skill set to run.\n\n## How it works\n\n- Store embeddings in a `vector(n)` column, where `n` matches your embedding model's dimension, 1536 for OpenAI's `text-embedding-3-small`, for example.\n- Query with a distance operator ordered by nearest match: `SELECT * FROM docs ORDER BY embedding <=> $1 LIMIT 10;`.\n- Build an **HNSW index** for fast approximate nearest-neighbor search at query time, or an **IVFFlat index** if you need faster builds and can tolerate slightly lower recall.\n- Combine the vector search with normal `WHERE` clauses in the same query — filter by tenant, date, or status alongside the similarity ranking, something a separate vector database makes far more awkward.\n\n## What changed in 2026\n\n- **HNSW is now the default recommendation** over IVFFlat for most workloads — better recall at similar query latency, at the cost of slower index builds.\n- **Iterative index scans** were added so filtered vector queries no longer silently under-return results when the filter is selective.\n- **`halfvec` and binary quantization** cut storage and memory footprint significantly for large embedding sets, making pgvector viable at tens of millions of rows.\n- **Every major managed Postgres provider ships it by default** — RDS, Supabase, Neon, Timescale, and Cloud SQL all support pgvector with no extra setup.\n\n## pgvector vs dedicated vector databases\n\n| Factor | pgvector | Pinecone / Weaviate / Qdrant |\n| --- | --- | --- |\n| Operational overhead | None — same Postgres instance | Separate service to run or pay for |\n| Joins with relational data | Native SQL | Requires app-side joins or duplication |\n| Max practical scale | Tens of millions of vectors, tuned | Billions, built for it |\n| Query latency at huge scale | Good with HNSW, degrades further out | Purpose-built, generally faster at extreme scale |\n| Best for | Most RAG apps, existing Postgres shops | Very large-scale, dedicated search products |\n\nIn practice, most teams default to pgvector and only evaluate a dedicated vector database after measuring a genuine bottleneck, index build time, query latency at extreme scale, or a need for features like multi-tenant namespacing that pgvector does not provide natively.\n\n## Common mistakes\n\n**Skipping the index and wondering why search is slow.** A sequential scan over embeddings is fine at a few thousand rows and falls apart past that — add an HNSW index before it becomes a production incident.\n\n**Mismatching the distance operator and how the model was trained.** Cosine-similarity models need `<=>`; using `<->` on normalized embeddings gives subtly wrong rankings.\n\n**Storing full-precision vectors when `halfvec` would do.** At millions of rows, halved storage is a real cost and memory win with minimal recall loss.\n\n**Assuming pgvector scales identically to a dedicated vector database.** It scales very well, but at extreme scale, hundreds of millions of vectors with tight latency SLAs, a purpose-built vector database still has an edge.\n\n## FAQ\n\n**Is pgvector fast enough for production RAG?**\nYes, for the overwhelming majority of RAG applications — millions of documents with an HNSW index comfortably hits sub-100ms queries.\n\n**Do I need a separate vector database if I already use Postgres?**\nUsually not. Add pgvector to your existing instance first, and only migrate to a dedicated vector database if you hit a specific, measured scale or latency wall.\n\n**What embedding dimension should my column use?**\nMatch it to your embedding model exactly — 1536 for OpenAI's small embedding model, 3072 for the large one, or whatever your chosen model outputs.\n\n**Can I combine full-text search with vector search?**\nYes — hybrid search, Postgres full-text search plus pgvector similarity, combined with reciprocal rank fusion, is a common and effective pattern in 2026.\n\n**Does pgvector support metadata filtering?**\nYes — because vectors live in ordinary Postgres rows, filtering by any column, tenant ID, category, or date is just a normal `WHERE` clause combined with the similarity ordering.\n\n## Where to go next\n\nFor the data-access side of a pgvector-backed app, [design patterns explained in 2026](/blog/design-patterns-explained-2026) covers the Repository pattern that keeps embedding queries out of your route handlers, and [how to build a REST API in Node in 2026](/blog/how-to-build-a-rest-api-in-node-2026) is a solid reference for the surrounding service. If you are hardening the same database, read [SQL injection prevention in 2026](/blog/sql-injection-prevention-guide-2026).","hue":304,"metaTitle":"pgvector Explained 2026: Vector Search in Postgres","metaDescription":"pgvector explained: how vector columns, distance operators, and HNSW indexes bring RAG and similarity search directly into Postgres in 2026.","keywords":["pgvector","pgvector explained","vector search in postgres","pgvector vs pinecone","postgres vector database","hnsw index postgres","pgvector rag embeddings","postgres for vector search 2026"],"tldr":["**One database instead of two** — embeddings live in a `vector` column alongside relational data, no separate vector database required.","**HNSW is now the default index** — better recall than IVFFlat at similar query latency, at the cost of slower index builds.","**halfvec and quantization cut storage** — pgvector now scales comfortably into tens of millions of rows on ordinary hardware.","**Every managed Postgres ships it** — RDS, Supabase, Neon, and Cloud SQL all support pgvector with no extra setup.","**Skip:** running vector queries with no index — a sequential scan over embeddings falls apart past a few thousand rows."],"readTime":"4 min read","wordCount":831},"related":[{"slug":"best-vector-databases-2026","title":"Best vector databases in 2026: ranked for RAG, scale, and cost","excerpt":"Vector databases power retrieval for AI apps, but the right pick depends on scale and budget. This guide ranks the leaders and the cheaper alternatives.","category":"code","date":"May 4, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":212},{"slug":"vector-databases-2026","title":"Vector databases in 2026: which one should you actually use?","excerpt":"The vector database market matured fast in 2026. Most apps do not need a dedicated vector DB — here is how to decide what you actually need.","category":"code","date":"April 29, 2026","author":"ByteLedger Team","readTime":"4 min read","hue":313},{"slug":"best-databases-for-ai-applications-2026","title":"Best databases for AI applications in 2026: vector + traditional ranked","excerpt":"Honest 2026 comparison of databases for AI apps — Postgres + pgvector vs Pinecone vs Qdrant vs Weaviate. When you need a dedicated vector DB and when you don't.","category":"code","date":"January 7, 2026","author":"ByteLedger Team","readTime":"2 min read","hue":320}],"sameCategory":[{"slug":"bazel-build-explained-2026","title":"Bazel Explained: What Hermetic Builds Actually Cost","excerpt":"Bazel delivers reproducible, precisely cached builds and demands that you describe everything. Here is what you get, what it costs, and who should say no.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":145},{"slug":"graphql-federation-2026","title":"GraphQL Federation: One Graph, Many Teams","excerpt":"Federation composes independently-owned subgraphs into a single API. Here is what it solves, the operational cost it adds, and when a simpler gateway is enough.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":300},{"slug":"hermetic-builds-explained-2026","title":"Hermetic Builds Explained: Same Inputs, Same Output","excerpt":"A hermetic build depends only on declared inputs. Here is what that property gives you, the common leaks that break it, and how to move toward it incrementally.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":130},{"slug":"monorepo-tooling-compared-2026","title":"Monorepo Tooling Compared: What You Actually Need","excerpt":"Monorepo tools solve task orchestration and caching, not repository layout. Here is what each tier provides and how to tell when you have outgrown the simple option.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":150}],"newer":{"slug":"pgbouncer-explained-2026","title":"PgBouncer Explained 2026: How Postgres Pooling Works","excerpt":"PgBouncer sits between your application and Postgres, multiplexing many client connections onto a small number of real database connections. Here is exactly how it does that, and which pool mode to pick.","category":"code","date":"August 7, 2026","author":"ByteLedger Team","readTime":"4 min read","hue":316},"older":{"slug":"platform-engineering-explained-2026","title":"Platform Engineering Explained in 2026: What It Is","excerpt":"Platform engineering builds internal infrastructure as a self-service product. Here is what these teams actually own and how they differ from DevOps.","category":"code","date":"August 7, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":308}}