RAG EngineeringIntermediate16 minModule · Ingest & index

Vector stores & index design

Choose where vectors live and tune the index for recall, latency, filters and scale.

See it on the map

For many products, vectors in your existing Postgres with pgvector are enough and keep data, permissions and joins in one place. Dedicated vector databases earn their place at large scale, with heavy filtering needs, or when you need features such as built-in hybrid search and managed scaling. Decide on corpus size, query rate, filter complexity and operational appetite.

HNSW is the common approximate index. Higher build-time and search-time effort settings raise recall and cost latency and memory. Tune them against exact search on a sample of your queries so you know the recall you are paying for. Product or scalar quantization shrinks memory further at some recall cost.

Filters are where designs break. Some stores apply metadata filters after the nearest-neighbour search, which can return fewer results than you asked for when the filter is selective. Check how your store handles filtering, and for permissions, partition or pre-filter so users can never receive restricted content even by accident.

Key points

  • Start with pgvector if your scale allows. Move when you can name the limit you hit.
  • Measure approximate-index recall against exact search on real queries.
  • Understand how your store combines filters with ANN search.
  • Never rely on the model to hide restricted results. Filter before retrieval.

Trade-offs

ChoiceYou gainYou pay
pgvector in PostgresOne system, joins, transactions, simple opsScaling and advanced features need more work
Dedicated vector DBScale, built-in hybrid search, managed opsAnother system to sync, secure and pay for

Answer these out loud

  1. 1A filter on tenant id matches 0.1% of vectors. What can go wrong with post-filtering and how do you avoid it?
  2. 2How would you choose HNSW search effort so p95 latency is under 50 ms with recall at least 0.95?

Build it

Load 100k embeddings into pgvector, build an HNSW index, and plot recall against search effort and latency versus exact search.

Use this from an agent

Any MCP client, including Grok, can read this lesson. See how to connect.

REST
curl https://engineeros-delta.vercel.app/api/v1/topics/rag-vector-store-and-indexing

This unlocks