Vector Databases
Course overview
A vector database stores “vectors + stable IDs + filterable metadata” and returns neighbors subject to authorization, business conditions, and resource budgets. Its job is not to “understand text”; it is a data and indexing system that covers:
- space schemas, dimensions, metrics, and version isolation;
- CRUD for points/records and idempotent writes;
- exact kNN and Approximate Nearest Neighbor (ANN) indexes;
- filters for tenants, ACLs, status, time, and other conditions;
- sharding, replicas, consistency, and scaling;
- snapshots, backup, recovery, migration, and operational monitoring.
A vector store cannot repair bad chunking, incorrect query/document roles, or embeddings that do not fit the task. Nor does a neighbor automatically become citable evidence. Complete retrieval also needs query rewriting, keyword/hybrid retrieval, reranking, context assembly, and evaluation.
Product-fact boundary
Collection, filter, HNSW/IVF parameters, write consistency, snapshot scope, and defaults vary by product and version. This course uses pgvector, Qdrant, Faiss, and PostgreSQL as verifiable examples, but does not generalize any product’s behavior into a guarantee for every vector database.
Where this course fits
Embeddings defines the vector-space contract, while Chunking Strategies and Knowledge Base Construction provide canonical points. This course owns storage, filtering, and neighbor queries. Then Semantic Search combines query encoding with multiple retrieval paths, Reranking refines candidates, and Retrieval-Augmented Generation (RAG) builds answers with citations.
Learning objectives
After completing this course, you should be able to:
- design a schema containing a space contract, point, vector, payload, source revision, ACL, and hash;
- distinguish exact kNN, ANN recall, and business Recall@k;
- explain the core intuition of HNSW, IVF, and quantization, including quality–latency–memory–build tradeoffs;
- make tenant/ACL/status filters fail closed before candidate scoring;
- implement stable IDs, explicit source CAS, idempotent upserts, delete-before-create fences, tombstones, and integrity reconciliation;
- state how shards, replicas, read/write acknowledgments, and concurrent updates can produce stale reads or conflicts;
- define RPO/RTO for a snapshot and prove it through an isolated restore drill;
- run a reproducible bake-off with real corpora, queries, filter distributions, and write mixes;
- identify the distinct responsibilities of a library, database extension, dedicated/managed vector store; and
- design dual-space/dual-read migration, shadow comparison, cutover, and rollback for a model or product move.
Prerequisites
- Vector Fundamentals: dot products, cosine, and Euclidean distance.
- Embeddings: space contracts, dimensions, metrics, normalization, and model migration.
- JSON: strict structures and types.
- APIs: retries, idempotency, rate limiting, and error handling.
You do not need prior distributed-database experience. Lessons 5–6 start with why an old value can be read and why a backup must be validated by a restore.
Core terms
| Term | Plain-language explanation | Critical boundary |
|---|---|---|
| point / record | One record containing an ID, vector, and payload | It must belong to one explicit embedding space. |
| collection / index / table | A product’s logical container | Names differ; isolation, transaction, and backup semantics differ too. |
| payload / metadata | Scalar data such as tenant, ACL, source, and status | It supports filtering and audit; it is not an arbitrary JSON junk drawer. |
| exact kNN | Compute distance against every candidate | A small-scale quality baseline. |
| ANN | Find approximate neighbors to reduce query cost | It can miss exact neighbors, so ANN recall must be measured. |
| scalar/payload index | An index on a filter field | It adds write/storage cost and should follow queries. |
| shard | A disjoint data partition of a collection | It affects routing, fan-out, and scaling. |
| replica | A copy of a shard | It improves availability/read capacity and introduces consistency tradeoffs. |
| tombstone | A logical record expressing the current deletion intent | Even an unindexed ID may need a fence; a current tombstone is not a permanent audit history. |
| snapshot / backup | A recoverable copy of state within a scope | Its scope, point in time, and inclusion of aliases/configuration must be explicit. |
Recommended sequence
| Order | Lesson | Learning outcome |
|---|---|---|
| 1 | Boundaries and the data model | A point/collection schema that is filterable, migratable, and auditable. |
| 2 | Distance, exact search, and ANN indexes | Exact ground truth and ANN-parameter experiments. |
| 3 | Filtering and multitenancy | Identity-derived tenant/ACL filters and unauthorized-access tests. |
| 4 | Writes, updates, deletes, and versioning | Source CAS, idempotent upserts, tombstone fences, publication switching, and deletion propagation. |
| 5 | Consistency, sharding, and replicas | Read/write semantics, shard keys, and fault tests. |
| 6 | Backup, recovery, and migration | RPO/RTO, snapshot manifests, and isolated restore drills. |
| 7 | Selection and benchmarking | A requirements matrix, reproducible bake-off, and ADR. |
| 8 | Project: toy vector store | Strict CRUD, source CAS, deletion intent, stale-read fail-closed behavior, and tests in a single-process JSON store. |
The first four lessons solve “is the data correct and safe?”; lessons 5–7 solve “what about scale, failures, and decisions?”; the final project turns the boundaries into code.
Hands-on entry point
- toy_vector_store.py: strict space contracts, persistence, source CAS, delete-before-create fences, explicit resurrection, stale-read checks, ACL/tenant filtering, and exact search.
- test_toy_vector_store.py: 41 tests for math, inputs, lifecycle, security, conflicts, persistence fences, resource boundaries, multi-instance stale reads, and the CLI.
The project uses only the Python standard library. From the vault root, create the teaching database in the system temporary directory:
$env:PYTHONDONTWRITEBYTECODE = '1' # Prevent the interpreter from creating __pycache__ in the course directory.
$db = Join-Path $env:TEMP ("toy-vector-store-" + [guid]::NewGuid().ToString("N") + ".json") # Generate a unique JSON database path in the system temporary directory.
python -B -W error '.\docs-EN\vector-databases\examples\toy_vector_store.py' --db $db demo # Run the toy store's create, update, search, and delete demonstration.
Remove-Item -LiteralPath $db -Force # Remove the explicitly created temporary database file after a successful demonstration.This project is not a production database: it has no multiprocess lock, complete transactions, ANN, authentication, replication, permanent lifecycle/audit ledger, or production disaster recovery. It validates file revision before public reads/no-ops and fails closed for stale instances, but a TOCTOU window still exists between the check and an actual read/write. Do not infer database-level consistency from it.
Mastery checklist
- Every collection/index has a complete space contract; incompatible vectors are never mixed.
- Point IDs, source revisions, content hashes, tenants, ACLs, statuses, and deletion states are traceable.
- I can distinguish exact search, ANN recall, and business relevance.
- An ANN benchmark reports quality, tail latency, throughput, memory, build cost, and update cost together.
- Tenant/ACL scope is derived from trusted identity and filtered before scoring; empty permission fails closed.
- An identical upsert can be replayed idempotently; a nonidentical update uses the expected-current source revision for CAS, and same-revision/different-content becomes a conflict.
- A delete records a source/event fence even when it precedes creation; a tombstone blocks resurrection by default, and resurrection requires an explicit matching fence and real authorization.
- A source identity for one point cannot be reused across lifecycles; a permanent generation/history ledger, not the current tombstone, carries ABA and audit history.
- Multi-instance cached state checks the revision before search, summary, and no-op behavior; a change fails closed instead of returning stale ACL or deletion state.
- Deletion propagates to vectors, sparse indexes, caches, old spaces, and backup policy.
- Shard, replica, and consistency choices implement explicit business read/write semantics.
- A snapshot is restored in isolation and checked for permissions and gold queries.
- Selection follows the target data, SLOs, team, and exit conditions—not a vendor’s single leaderboard.
Relationship to other courses
| Course | Relationship |
|---|---|
| Chunking Strategies | Produces the source spans and content hashes represented by points. |
| Embeddings | Defines dimensions, metrics, normalization, model, and revision. |
| Knowledge Base Construction | Provides canonical revisions, an outbox, published pointers, and deletion events. |
| Semantic Search | Organizes queries, filters, vector/keyword retrieval, and offline relevance. |
| Reranking | Consumes first-stage candidates; it does not replace database retrieval. |
| RAG | Packages and cites authorized evidence, then produces an answer. |
| Runtime Monitoring | Observes latency, errors, capacity, replication, indexing, and recovery. |
| AI Safety | Covers unauthorized access, data poisoning, log risk, and backup risk. |
Primary references
- pgvector official repository
- Faiss official repository
- Qdrant Documentation
- Qdrant: Points
- Qdrant: Filtering
- Qdrant: Distributed deployment
- Qdrant: Snapshots
- PostgreSQL: Transactions
- PostgreSQL: Backup and Restore
- Malkov & Yashunin, HNSW
- Johnson, Douze & Jégou, Billion-scale similarity search with GPUs
Sources retrieved on 2026-07-22. Dynamic product configuration, defaults, and guarantees must be rechecked against the pinned version.