RAG for Everyone

← Back to all chapters

Chapter 15 of 28Vector Stores80 min read

Vector Stores and Indexing Strategies

A vector store is not just a database for embeddings. In production RAG, it is the retrieval control plane: ids, metadata, collections, index versions, filters, refreshes, rebuilds, and release strategies all decide whether the right evidence reaches the model.

How to read this chapter

Bad vector-store design can make a good embedding model look terrible. The retriever cannot return evidence that was stored badly, filtered wrongly, or released unsafely.
Core ideaA vector store stores embeddings plus the document text, metadata, ids, and index structures needed to search, filter, retrieve, trace, and release knowledge safely.
Sub-topic 1 of 14

Why Vector Stores Matter

At a glance
  • Vector stores hold embeddings, source text, ids, metadata, and collection settings.
  • Index design affects recall, latency, storage, cost, and reliability.
  • Metadata filters enforce freshness, access, tenant, source, and version rules.
  • Production systems need rebuild, rollback, and blue-green index releases.

In a demo, you can throw vectors into memory and search them. In production, users ask sensitive questions, documents update, permissions change, models evolve, and old policies must disappear. The vector store becomes part of your product's safety and reliability story.

Vector-store north starStore knowledge so it can be retrieved, filtered, cited, audited, refreshed, and rolled back.

The goal is not only fast nearest-neighbor search. The goal is trustworthy retrieval operations.

01
Choose collection boundaries

Separate tenants, environments, domains, model dimensions, and release versions when needed.

02
Design stable ids

Chunk ids should connect to source id, version, section, parent, and index release.

03
Attach metadata

Access, freshness, source type, owner, effective date, and status power safe filters.

04
Release with evals

New indexes should pass golden queries before traffic shifts.

Sub-topic 2 of 14

Real-Life Analogy: A Warehouse With Labels

A warehouse is only useful if items are stored with labels, locations, categories, batch numbers, and expiry dates. If everything is thrown into one pile, you technically have storage, but you do not have operations.

A vector store works the same way. The vector is the item location in meaning space. Metadata is the label. The collection is the warehouse section. The index is the route map. The release version is the batch record.

Mental picture
  • Collection: warehouse section.
  • Vector: searchable location.
  • Metadata: labels and rules.
  • Index version: batch release.
Sub-topic 3 of 14

Core Concepts

Embedding

The numeric vector used for similarity search.

Document text

The chunk content returned to the prompt after retrieval.

Metadata

Structured fields used for filters, permissions, citations, freshness, and debugging.

Stored vector record

{
  "id": "refund_policy:v3:section_04:chunk_02",
  "text": "EU annual plan renewals are refundable within...",
  "embedding": [0.018, -0.223, ...],
  "metadata": {
    "source_id": "refund_policy",
    "version": "v3",
    "status": "active",
    "region": "EU",
    "access": "support",
    "effective_date": "2026-04-01",
    "embedding_model": "embed-model-a",
    "index_version": "refund-index-2026-07-11"
  }
}
Sub-topic 4 of 14

Collections and Schemas

A collection groups vectors that share a compatible shape and retrieval purpose. Do not treat collection design casually.

Environment

dev, staging, prod

Keep experimental indexes away from production traffic.

Tenant

customer or org boundary

Strict tenant separation can simplify access control and deletion.

Model

dimension compatibility

Collections usually assume one vector dimension and model family.

Domain

policy, docs, support

Domain collections can improve ownership and targeted rebuilds.

Sub-topic 5 of 14

Index Strategies

Vector indexes trade recall, speed, memory, and complexity. The names differ by database, but the production questions are similar.

Flat search

Compares query vector against every vector. Simple and accurate, but slow at large scale.

Approximate search

Uses structures such as HNSW or IVF-style approaches to search faster with possible recall trade-offs.

Hybrid index

Combines dense vector search with sparse keyword search, filters, or reranking.

Production trade-off

Fast is not enough

A low-latency approximate index that misses critical policy chunks is not better than a slower index that answers correctly. Measure recall and latency together.

Sub-topic 6 of 14

Index Lifecycle

Lifecycle stages

source change
  -> parse and clean
  -> chunk
  -> embed
  -> upsert to staging index
  -> run retrieval evals
  -> promote index version
  -> monitor production traces
  -> roll back if needed

Refreshing an index is not just "insert new vectors." You need clear decisions for updates, deletes, stale chunks, failed embedding jobs, partial rebuilds, and index promotion.

Sub-topic 7 of 14

Architecture View

Vector store architecture with ingestion, embedding, staging index, eval gate, production index, query retrieval, filters, and rollback
Production vector-store architecture separates build, evaluation, promotion, query-time filtering, and rollback.

Query-time retrieval

user question
  -> query embedding
  -> metadata filters
  -> vector search
  -> optional sparse / hybrid merge
  -> rerank
  -> context assembly
  -> citation and trace
Sub-topic 8 of 14

Production Operations

Production gear
  • Idempotent upserts: repeated ingestion should not duplicate chunks.
  • Deletes: retired or restricted documents must be removed or filtered reliably.
  • Backfills: large rebuilds need progress tracking and resume support.
  • Dimension checks: reject vectors that do not match collection dimensions.
  • Traceability: log collection, index version, filters, ids, scores, and citations.
  • Access control: enforce filters before context reaches the model.
  • Disaster recovery: snapshot or rebuild strategy must be documented.
Sub-topic 9 of 14

Release Strategies

In-place

Update current index

Simple, but risky if rebuild goes wrong or partial updates leak into production.

Blue-green

Build new index beside old

Run evals on green, then switch traffic when ready. Safer for major changes.

Shadow

Compare without serving

Run the new index against real queries and compare results before rollout.

Canary

Gradual traffic shift

Expose a small percentage of traffic and monitor failures before full release.

Sub-topic 10 of 14

Metrics

Retrieval quality

Recall@k, MRR, gold chunk rank, citation support, duplicate rate, stale-hit rate.

Operations

Index build duration, upsert failures, delete lag, embedding failures, dimension mismatches.

Runtime

Query latency, filter selectivity, timeout rate, top-k distribution, empty result rate.

Sub-topic 11 of 14

Common Mistakes

M01

Storing vectors without source text

Symptom: retrieval returns ids but the system cannot assemble grounded context.
Better move: store text or reliable source pointers with every vector.
M02

Weak chunk ids

Symptom: updates create duplicates or citations cannot be traced.
Better move: use deterministic ids with source, version, section, and chunk position.
M03

No metadata filters

Symptom: stale, restricted, or wrong-tenant content appears in answers.
Better move: design metadata schema before indexing.
M04

Mixing dimensions

Symptom: vectors fail writes or search behavior becomes invalid.
Better move: enforce collection dimension and model compatibility.
M05

Rebuilding directly in production

Symptom: partial indexes serve user traffic.
Better move: build staging index, eval, then promote.
M06

Ignoring deletes

Symptom: retired policies still answer user questions.
Better move: implement delete or active-status filters with audits.
M07

Optimizing latency before recall

Symptom: fast retrieval misses critical evidence.
Better move: tune approximate search with recall evals.
M08

No index rollback

Symptom: a bad index release cannot be reversed quickly.
Better move: keep previous index version available until new release is proven.
Sub-topic 12 of 14

Interview-Level Understanding

A strong answer sounds like this: "A vector store stores embeddings with ids, source text, metadata, and index structures for similarity search. In production, I design collections by dimension, tenant, domain, and environment, enforce metadata filters, version index releases, and use blue-green rebuilds with retrieval eval gates."

Senior signal

What separates demo and production?

A demo says "we put embeddings in a vector DB." Production says "we can explain every retrieved chunk, filter unsafe chunks, rebuild safely, compare versions, and roll back if retrieval quality drops."

Sub-topic 13 of 14

Mini Assignment

Design a vector-store schema for a policy assistant. Include collection boundaries, id format, required metadata, index release strategy, delete behavior, and five metrics you would monitor after release.

Sub-topic 14 of 14

Points To Remember

  • A vector store stores more than vectors: it stores retrieval trust.
  • Stable ids and metadata are production-critical.
  • Index choices trade recall, latency, memory, and cost.
  • Major changes should use staging indexes, eval gates, and rollback plans.
  • Vector-store traces should explain what was searched, filtered, retrieved, and cited.

Next, test vector-store judgment in the quiz, then build an index release planner in exercises and project.

← Chapter 14 ProjectTake the Quiz →