Back to Blogs
Article

Running pgvector in Production: Real-Time Embeddings at Scale

Running pgvector in Production: Real-Time Embeddings at Scale
  <h2>Why You Might Not Need a Dedicated Vector Database</h2>
  <p>While standalone vector databases like Pinecone and Weaviate are powerful, storing your vector embeddings directly inside PostgreSQL using <code>pgvector</code> eliminates dual-writes, sync lag, and distributed transaction headaches.</p>

  <h3>HNSW vs. IVFFlat: The Decisive Index Choice</h3>
  <p>In modern PostgreSQL deployments, always prefer the <strong>HNSW (Hierarchical Navigable Small World)</strong> index over IVFFlat:</p>
  <ul>
    <li><strong>Zero Training Requirement:</strong> HNSW indexes build incrementally as records are inserted without needing batch re-training.</li>
    <li><strong>Superior Recall:</strong> Delivers 95%+ recall even at sub-5ms query latencies.</li>
    <li><strong>Memory Considerations:</strong> Ensure <code>maintenance_work_mem</code> is tuned sufficiently high during index construction.</li>
  </ul>

  <p>By keeping user data, relational permissions, and vector embeddings in a single database, your AI queries can leverage standard SQL joins with zero network hops.</p>
Published by Boad
Read more articles