← Master Index
Vol. 14 Module 14.1 Lecture

Vector Database

RAG Core Concepts

How This Lesson Fits the Module & Volume

Retrieval needs somewhere to store vectors, IDs, and metadata. A vector database (or vector-capable store) provides ANN indexes, filters, and CRUD for embeddings at scale. Module 14.2 will deepen with FAISS and friends; here we establish the product concept and ops responsibilities.

Learning Objectives

By the end of this lesson, students should be able to:

  • Define a vector database as storage + ANN search over embeddings.
  • Contrast libraries (FAISS) vs managed vector DBs vs pgvector-style extensions.
  • List core operations: upsert, delete, search, filter, backup.
  • Explain why payload/metadata is first-class for RAG tenancy and citations.
  • Identify scaling concerns: RAM, replicas, index rebuilds.
  • Preview vector search as the query API over that store.
Definition

A vector database is a system optimized to store high-dimensional vectors with identifiers and metadata, and to answer nearest-neighbor queries efficiently (often via approximate indexes), optionally with filtered search.

Deployment Shapes

ShapeExampleTradeoff
Library / embeddedFAISS in-processFast; you own durability & HA
DB extensionpgvectorSQL joins; ANN maturity varies
Managed vector DBCloud servicesOps ease; vendor & cost model

Must store

  • Vector + id
  • Chunk text or pointer
  • Filterable metadata

Must support

  • k-NN / ANN search
  • Upsert & delete
  • Metric choice

Nice to have

  • Hybrid sparse+dense
  • Multi-tenant isolation
  • Snapshots / CDC

Code: In-Memory Store Sketch

import numpy as np from dataclasses import dataclass @dataclass class Row: id: str vector: np.ndarray text: str metadata: dict class TinyVectorDB: def __init__(self): self.rows: list[Row] = [] def upsert(self, row: Row): self.rows = [r for r in self.rows if r.id != row.id] + [row] def search(self, q: np.ndarray, k: int = 5, where: dict | None = None): cand = self.rows if where: cand = [r for r in cand if all(r.metadata.get(k_) == v for k_, v in where.items())] if not cand: return [] M = np.stack([r.vector for r in cand]) scores = M @ q # assumes L2-normalized idx = np.argsort(-scores)[:k] return [(cand[i], float(scores[i])) for i in idx] # Production: replace brute force with ANN (HNSW/IVF) — see Indexing / FAISS.

Strengths

  • Purpose-built for similarity
  • Filters + vectors in one query
  • Scales beyond numpy loops

Tradeoffs

  • Another system to operate
  • Index params affect recall
  • Re-embed storms on model change
Common Misconception

“A vector DB replaces our document store.” Usually you still keep canonical documents in object storage or a CMS; the vector DB indexes derived chunks. Treat vectors as a search projection, not the system of record.

Knowledge Check

  1. Short Answer: What query type are vector DBs optimized for? Answer: Nearest-neighbor / similarity search over vectors.
  2. True/False: Metadata is optional noise in RAG indexes. Answer: False—filters, tenancy, and citations depend on it.
  3. Multiple Choice: FAISS is best described as: (a) a library, (b) a social network, (c) a CSS framework. Answer: (a).
  4. Short Answer: Name one vector DB deployment shape. Answer: Embedded library, DB extension, or managed service.
  5. True/False: Upsert/delete matter for fresh knowledge bases. Answer: True.
  6. Multiple Choice: System of record for docs should usually be: (a) only ANN graph, (b) canonical doc store + vector projection, (c) browser cookies. Answer: (b).
  7. Short Answer: Why does model change stress a vector DB? Answer: All vectors must be re-embedded and re-indexed.
  8. True/False: Brute-force search scales forever. Answer: False—use ANN at scale.
  9. Multiple Choice: Next lecture: (a) Vector Search, (b) Vol. 1 only, (c) printers. Answer: (a).
  10. Short Answer: What does filtered search combine? Answer: Metadata predicates with vector similarity.

Key Takeaways

  • Vector DBs store embeddings + metadata for ANN retrieval.
  • Choose library vs managed vs SQL-extension based on ops needs.
  • Keep canonical documents elsewhere; index is a projection.
  • Next: Vector Search.
Trainer’s Guide

Lab: Implement TinyVectorDB; then discuss which production features are missing for a 10M-chunk corpus.

Prompt: When is pgvector enough vs a dedicated vector service?

Recap: Vector databases host the searchable projection of your knowledge base. Continue with Vector Search.