---
title: "RAG With Autoscaling: Better Performance With Lower Costs For pgvector"
description: "Neon's autoscaling lets a Postgres instance scale up temporarily for the heavy memory and CPU demands of pgvector HNSW index builds, then scale back down, instead of being permanently overprovisioned."
url: "https://swe.quest/articles/rag-with-autoscaling-better-performance-with-lower-costs-for-pgvector-52ce2e1857682b4f"
canonical: "https://neon.com/blog/rag-with-autoscaling"
source: "Neon"
published: "2024-08-27"
difficulty: "medium"
kind: "Announcement"
reading_minutes: 4
tags: ["vector-search","postgres","capacity-planning","rag","cost-optimization"]
---

# RAG With Autoscaling: Better Performance With Lower Costs For pgvector

A post on [Neon](https://swe.quest/sources/neon.md), published 2024-08-27, 4 min read, Announcement. Original: [https://neon.com/blog/rag-with-autoscaling](https://neon.com/blog/rag-with-autoscaling)

## Summary

Neon's autoscaling lets a Postgres instance scale up temporarily for the heavy memory and CPU demands of pgvector HNSW index builds, then scale back down, instead of being permanently overprovisioned. On a 1M-row table, a sequential-scan similarity query took about 3 seconds, while an HNSW index cut it to about 1 ms. Building that index used 8 parallel workers and 8GB of maintenance\_work\_mem and produced a ~7.8GB index. Because maintenance\_work\_mem is allocated upfront, Neon backs it with disk swap so a small compute can accept an 8GB setting, swapping data back into memory as the autoscaler adds compute units.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Vector search](https://swe.quest/tags/vector-search.md) (Data & databases)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Capacity planning](https://swe.quest/tags/capacity-planning.md) (Reliability & operations)
- [RAG & retrieval](https://swe.quest/tags/rag.md) (AI & ML)
- [Cost optimization](https://swe.quest/tags/cost-optimization.md) (Reliability & operations)

## Prerequisites

- PostgreSQL indexes ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- vector embeddings ([easy posts on RAG & retrieval](https://swe.quest/tags/rag.md?difficulty=easy))
- EXPLAIN ANALYZE

## Keywords

Neon, pgvector, HNSW, maintenance\_work\_mem, Neon Autoscaling

## Related posts

- [pgvector: 30x Faster Index Build for your Vector Embeddings](https://swe.quest/articles/pgvector-30x-faster-index-build-for-your-vector-embeddings-cd6dabfa49eb13de.md): Neon · 2024-02-07 · Medium · 6 min read · Vector search, PostgreSQL, Performance engineering
  pgvector 0.6.0 adds parallel builds for HNSW indexes, cutting build time by up to 30x in benchmarks on 10M 1,536-dimension vectors using a 64 vCPU, 512GB instance.
- [pgvector 0.6.0: 30x faster with parallel index builds](https://swe.quest/articles/pgvector-0-6-0-30x-faster-with-parallel-index-builds-e5dea50876a1e20f.md): Supabase · 2024-01-30 · Medium · 3 min read · Vector search, PostgreSQL, Performance engineering
  pgvector 0.6.0 adds parallel HNSW index builds, cutting build time for 1M 1536-dimension vectors (dbpedia OpenAI dataset, m=16, ef\_construction=200) from about 1h27m to 9.5 minutes.
- [On-disk HNSW index for Postgres with pg\_embedding](https://swe.quest/articles/on-disk-hnsw-index-for-postgres-with-pg-embedding-aadc4bd81ebf65c4.md): Neon · 2023-08-03 · Medium · 5 min read · Vector search, PostgreSQL
  pg\_embedding's new version builds its HNSW vector index on disk rather than in memory and adds cosine, Manhattan and Euclidean (L2) distance support.
- [Hosting Postgres with pgvector: provider tradeoffs, migrations, indexes, and tuning](https://swe.quest/articles/hosting-postgres-with-pgvector-provider-tradeoffs-migrations-indexes-and-tuning-5801c10912bf8686.md): Railway · 2025-12-15 · Medium · 9 min read · PostgreSQL, Vector search, Schema migrations, Performance engineering
  Running pgvector well depends on hosting that allows extension and configuration control, migrations wired into the deploy pipeline, and the right index choice.
- [1 Year of Autoscaling Postgres: How it’s going, and what’s next](https://swe.quest/articles/1-year-of-autoscaling-postgres-how-it-s-going-and-what-s-next-a75ce75d92118903.md): Neon · 2024-04-15 · Hard · 8 min read · PostgreSQL, Virtualization, Capacity planning, Memory management, Kubernetes
  Neon autoscales Postgres by running each instance as a VM in Kubernetes (NeonVM), with a per-node autoscaler-agent, a modified scheduler, and an in-VM vm-monitor that resizes the Local File Cache.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
