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

TermPlain-language explanationCritical boundary
point / recordOne record containing an ID, vector, and payloadIt must belong to one explicit embedding space.
collection / index / tableA product’s logical containerNames differ; isolation, transaction, and backup semantics differ too.
payload / metadataScalar data such as tenant, ACL, source, and statusIt supports filtering and audit; it is not an arbitrary JSON junk drawer.
exact kNNCompute distance against every candidateA small-scale quality baseline.
ANNFind approximate neighbors to reduce query costIt can miss exact neighbors, so ANN recall must be measured.
scalar/payload indexAn index on a filter fieldIt adds write/storage cost and should follow queries.
shardA disjoint data partition of a collectionIt affects routing, fan-out, and scaling.
replicaA copy of a shardIt improves availability/read capacity and introduces consistency tradeoffs.
tombstoneA logical record expressing the current deletion intentEven an unindexed ID may need a fence; a current tombstone is not a permanent audit history.
snapshot / backupA recoverable copy of state within a scopeIts scope, point in time, and inclusion of aliases/configuration must be explicit.
OrderLessonLearning outcome
1Boundaries and the data modelA point/collection schema that is filterable, migratable, and auditable.
2Distance, exact search, and ANN indexesExact ground truth and ANN-parameter experiments.
3Filtering and multitenancyIdentity-derived tenant/ACL filters and unauthorized-access tests.
4Writes, updates, deletes, and versioningSource CAS, idempotent upserts, tombstone fences, publication switching, and deletion propagation.
5Consistency, sharding, and replicasRead/write semantics, shard keys, and fault tests.
6Backup, recovery, and migrationRPO/RTO, snapshot manifests, and isolated restore drills.
7Selection and benchmarkingA requirements matrix, reproducible bake-off, and ADR.
8Project: toy vector storeStrict 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

CourseRelationship
Chunking StrategiesProduces the source spans and content hashes represented by points.
EmbeddingsDefines dimensions, metrics, normalization, model, and revision.
Knowledge Base ConstructionProvides canonical revisions, an outbox, published pointers, and deletion events.
Semantic SearchOrganizes queries, filters, vector/keyword retrieval, and offline relevance.
RerankingConsumes first-stage candidates; it does not replace database retrieval.
RAGPackages and cites authorized evidence, then produces an answer.
Runtime MonitoringObserves latency, errors, capacity, replication, indexing, and recovery.
AI SafetyCovers unauthorized access, data poisoning, log risk, and backup risk.

Primary references

Sources retrieved on 2026-07-22. Dynamic product configuration, defaults, and guarantees must be rechecked against the pinned version.