Back to blog

pgvector Architecture Diagram: Postgres as Your Vector Database (2026)

How to create pgvector architecture diagrams for Postgres-native vector search. Covers HNSW vs IVFFlat indexing, hybrid search, row-level security for multi-tenant RAG, connection pooling, and managed platforms like Supabase and Neon — with AI prompt templates.

R
Ryan·Senior AI Engineer
·

pgvector architecture diagrams have become one of the most requested diagram types in 2026 as teams realize they don't need a dedicated vector database to ship RAG or semantic search. pgvector — the open-source Postgres extension for storing and querying embeddings — turns any Postgres instance into a vector store, which means the “architecture diagram” question shifts from “which vector DB do we add?” to “how do we model vector search as part of the Postgres system we already run?” This guide covers the components, indexing tradeoffs, and prompt templates for diagramming a pgvector-based system.

Why pgvector over a dedicated vector database

  • Operational simplicity: One database to provision, monitor, back up, and secure instead of two. No separate vector DB cluster with its own auth, networking, and upgrade cadence.
  • Transactional consistency: Vector embeddings live in the same transaction as the relational data they describe. Insert a document row and its embedding atomically — no eventual-consistency gap between the source-of-truth database and a separate vector index.
  • Cost: No extra per-vector or per-query pricing on top of your existing Postgres bill. For most RAG workloads under tens of millions of vectors, a right-sized Postgres instance is dramatically cheaper than a managed vector DB tier with equivalent throughput.
  • SQL-native joins: Filter vector search results by relational columns (tenant_id, permissions, created_at) in the same query using standard WHERE clauses — no separate metadata filtering API to learn.
  • When a dedicated vector DB still wins: Billions of vectors, sub-10ms p99 latency requirements, or workloads that need purpose-built ANN algorithms (DiskANN, SPANN) and horizontal sharding that Postgres doesn't natively provide. Pinecone, Weaviate, Qdrant, and Milvus remain the right call at that scale.

Core components of a pgvector architecture diagram

  • Application / ingestion service: The service that chunks source documents, calls an embedding model, and writes rows into Postgres. Show this as a distinct box even when it's a background worker rather than the request-serving app.
  • Embedding model: OpenAI text-embedding-3-large/-small, Voyage AI, or Cohere Embed — called at ingestion time and again at query time to embed the user's search string. Annotate the dimension count (e.g., 1536, 1024) since it determines the vector column's width.
  • Postgres instance with pgvector enabled: CREATE EXTENSION vector; on the target database. Show this as the central node — it's both the relational store and the vector store.
  • Vector column + index: A vector(1536) column plus an ANN index. Annotate HNSW vs IVFFlat — HNSW is the 2026 default because it gives better query-time recall/speed tradeoffs without needing a pre-training pass, while IVFFlat is faster to build and lighter on memory for smaller, mostly-static datasets.
  • Hybrid search layer: Combining pgvector's cosine or L2 distance operators (<=>, <->) with native Postgres full-text search (tsvector/tsquery, ts_rank) and re-ranking (often reciprocal rank fusion) to catch exact keyword matches that pure semantic search misses.
  • Row-level security (RLS): Postgres RLS policies scoped to tenant_id or user_id so vector similarity queries automatically stay within a caller's allowed rows — critical for multi-tenant SaaS RAG.
  • Connection pooling: PgBouncer or Supabase's Supavisor sitting in front of Postgres. HNSW index builds and high-concurrency embedding writes are memory- and connection-intensive, so pooling protects against connection exhaustion under load.

Managed pgvector platforms

  • Supabase: Postgres with pgvector pre-installed, built-in Supavisor pooling, RLS-first auth model, and Edge Functions for embedding pipelines — the most common pick for RAG apps built by small teams.
  • Neon: Serverless Postgres with pgvector support and branchable databases, useful for testing index/embedding changes on a full data copy without touching production.
  • AWS RDS / Aurora PostgreSQL: pgvector support on managed Postgres inside existing AWS infrastructure — the default choice when the rest of the stack (IAM, VPC, other RDS databases) already lives in AWS.
  • Timescale (TigerData): Postgres with pgvector plus TimescaleDB's columnar compression and pgvectorscale extension, aimed at teams that also need time-series data alongside embeddings.
  • Google Cloud SQL for PostgreSQL: Managed Postgres with pgvector support for teams standardized on GCP, often paired with Vertex AI embedding models.

Prompt examples for pgvector architecture diagrams

Full RAG pipeline on Supabase with pgvector

"RAG pipeline built on Supabase Postgres with pgvector. Ingestion: documents uploaded to Supabase Storage → Edge Function chunks text (500 tokens, 50 token overlap) → calls OpenAI text-embedding-3-small (1536 dims) → writes rows into a 'document_chunks' table (columns: id, document_id, content, embedding vector(1536), tenant_id) via Supavisor pooled connection. Table has an HNSW index (m=16, ef_construction=64) on the embedding column using vector_cosine_ops. Query path: user submits question in web app → Next.js API route embeds the query with the same model → runs a Postgres RPC function performing 'embedding <=> query_embedding' cosine distance search with LIMIT 8 → results passed as context to GPT-4o for answer generation → response streamed back to user. Show ingestion and query paths as separate flows converging on the same Postgres/pgvector store, with Supavisor pooling in front of Postgres."

Multi-tenant SaaS app with RLS-isolated vector search

"Multi-tenant SaaS RAG architecture with pgvector and row-level security. Single Postgres database (AWS RDS Aurora) shared across all tenants, 'embeddings' table with tenant_id column and HNSW index. RLS policy 'tenant_isolation' enforces 'tenant_id = current_setting(\\'app.current_tenant\\')::uuid' on SELECT — every similarity search automatically scopes to the caller's tenant with zero application-level filtering logic. Application layer: API gateway authenticates request → sets tenant context via 'SET app.current_tenant' in a transaction → runs cosine similarity query through PgBouncer (transaction pooling mode, since session-level SET requires care with pooling) → returns only that tenant's matching chunks. Show the RLS policy boundary explicitly as a security layer wrapping the vector table, distinct from the connection pooling layer, with an annotation that transaction-mode pooling requires per-transaction SET rather than per-session SET."

Hybrid search combining pgvector and tsvector

"Hybrid search architecture combining pgvector semantic search with native Postgres full-text search. 'articles' table has an 'embedding vector(1024)' column (Voyage AI embeddings, HNSW index) and a generated 'search_vector tsvector' column (GIN index) built from title + body. Query flow: user query is embedded (semantic path) and also passed through 'plainto_tsquery' (keyword path) in parallel. Semantic path returns top 20 by cosine distance; keyword path returns top 20 by ts_rank. Results merged with reciprocal rank fusion (RRF, k=60) in a Postgres CTE, producing a single ranked list. Show both search paths as parallel branches from the same query input, converging at an RRF ranking step before results are returned to the application. Annotate that this catches exact-match queries (product SKUs, error codes) that pure vector search misses."

HNSW index tuning and connection pooling under load

"pgvector scaling architecture showing HNSW index tuning under concurrent embedding writes. Ingestion workers (5 parallel processes) bulk-insert ~2M embeddings/day into a 'vectors' table. HNSW index build parameters: m=24 (higher than default for better recall at this scale), ef_construction=100, maintenance_work_mem set to 2GB during index builds to avoid disk-based graph construction. Writes go through PgBouncer in transaction pooling mode with a pool size of 25 to prevent connection exhaustion, since each HNSW insert briefly holds more memory than a typical OLTP write. Read replicas (2x) serve query traffic with ef_search=100 tuned per-session for the recall/latency tradeoff, while the primary handles writes only. Show: ingestion workers → PgBouncer → Postgres primary (HNSW index, writes) → streaming replication → read replicas (query traffic) → application. Annotate memory settings and pool size next to the primary."

pgvector vs dedicated vector databases

ToolApproachBest forLimitations
pgvectorVector extension on existing PostgresTeams already on Postgres, transactional consistency, cost-sensitive RAGScales to tens of millions of vectors comfortably, not billions
PineconeFully managed, purpose-built vector DBMassive scale, minimal ops overhead, serverless pricingSeparate system from relational data, usage-based cost at scale
WeaviateOpen-source vector DB with built-in modulesGraphQL-native apps, hybrid search out of the boxSelf-hosting adds operational complexity
QdrantRust-based vector DB, rich filteringHigh-performance filtered search, on-prem or cloudSmaller ecosystem than Postgres tooling
MilvusDistributed vector DB, purpose-built ANN enginesBillions of vectors, sub-10ms p99 at scaleHeaviest operational footprint of this group

What to annotate on a pgvector architecture diagram

  • Index type: HNSW or IVFFlat, with the build parameters (m, ef_construction for HNSW; lists for IVFFlat) that affect recall and build time.
  • Vector dimensions: The embedding model's output dimension (e.g., 1536, 1024) — it determines column width and storage/index size.
  • Distance metric: Cosine, L2, or inner product — must match the operator class used when the index was created, or the index won't be used.
  • Connection pool size and mode: PgBouncer/Supavisor pool size and pooling mode (session vs transaction), since HNSW builds and bulk embedding writes are memory-heavy.
  • RLS policies: Which policies scope vector queries by tenant or user, so security boundaries are visible without reading application code.
  • ef_search / query-time tuning: The recall/latency knob set per query session — worth showing since it's often tuned differently for read replicas vs primary.

Related guides: vector database architecture, RAG architecture diagrams, agentic RAG architecture, and RAG pipeline use cases.

Ready to try it yourself?

Start Creating - Free