COS 597A

Long Term Memory in AI — Vector Search and Databases (COS 597A, Fall 2023)

Long Term Memory in AI — Vector Search and Databases
COS 597A · Fall 2023 · Princeton University

Class Description

Long Term Memory is a foundational capability in the modern AI Stack. At their core, these systems use vector search. Vector search is also a basic tool for systems that manipulate large collections of media like search engines, knowledge bases, content moderation tools, recommendation systems, etc.

As such, the discipline lies at the intersection of Artificial Intelligence and Database Management Systems. This course covers the theoretical foundations and practical implementation of vector search applications, algorithms, and systems — ranging from text and image embeddings to dimensionality reduction, locality-sensitive hashing, clustering, vector quantization, and graph-based approximate nearest neighbor indexes. The course is evaluated with a final project and in-class presentation.

Syllabus & Class Notes

  • Class 1 (9/8) — Introduction to Vector Search (PDF) [Matthijs + Edo + Nataly]

    • Intro to the course: Topic, Schedule, Project, Grading, …
    • Embeddings as an information bottleneck: instead of learning end-to-end, use embeddings as an intermediate representation.
    • Advantages: scalability, instant updates, and explainability.
    • Typical volumes of data and scalability: embeddings are the only way to manage and access large databases.
    • The embedding contract: the embedding extractor and embedding indexer agree on the meaning of the distance. Separation of concerns.
    • The vector space model in information retrieval.
    • Vector embeddings in machine learning.
    • Definitions: vector, vector search, ranking, retrieval, recall.
  • Class 2 (9/15) — Text Embeddings (PDF) [Matthijs]

    • 2-layer word embeddings: Word2vec and fastText, obtained via a factorization of a co-occurrence matrix. Embedding arithmetic: king + woman − man = queen (already based on similarity search).
    • Sentence embeddings: how to train, masked language models, properties of sentence embeddings.
    • Large Language Models: reasoning as an emerging property of an LM; what happens when the training set equals the whole web.
  • Class 3 (9/22) — Image Embeddings (PDF) [Matthijs]

    • Pixel structures of images and early works on direct pixel indexing.
    • Traditional computer vision models: global descriptors (GIST), local descriptors (SIFT and friends), direct indexing of local descriptors for image matching, local descriptor pooling (Fisher, VLAD).
    • Convolutional Neural Networks: off-the-shelf models and models trained specifically via contrastive learning and self-supervised learning.
    • Modern computer vision models.
  • Class 4 (9/29) — Low Dimensional Vector Search (PDF) [Edo]

    • Vector search problem definition.
    • k-d trees and space-partitioning data structures.
    • Worst-case proof for k-d trees.
    • Probabilistic inequalities: recap of Markov, Chernoff, and Hoeffding inequalities.
    • Concentration of measure phenomena and orthogonality of random vectors in high dimensions.
    • Curse of dimensionality and the failure of space partitioning.
  • Class 5 (10/6) — Dimensionality Reduction (PDF) [Edo]

    • Singular Value Decomposition (SVD) and applications of the SVD.
    • Rank-k approximation in the spectral norm and Frobenius norm.
    • Linear regression in the least-squares loss.
    • Principal Component Analysis (PCA): optimal squared-loss dimension reduction and closest orthogonal matrix.
    • Computing the SVD: the power method.
    • Random projections: matrices with normally distributed independent entries and Fast Random Projections (FJLT).
  • Class 6 (10/27) — Approximate Nearest Neighbor Search (PDF) [Edo]

    • Definition of Approximate Nearest Neighbor Search (ANNS).
    • Evaluation criteria: speed, accuracy, memory usage, updateability, and index construction time.
    • Definition of Locality Sensitive Hashing (LSH) and examples.
    • The LSH algorithm, analysis, proof of correctness, and asymptotics.
  • Class 7 (11/3) — Clustering (PDF) [Edo]

    • k-means clustering: mean squared error criterion.
    • Lloyd’s algorithm.
    • k-means and PCA.
    • ε-net argument for fixed dimensions.
    • Sampling-based seeding for k-means and k-means++.
    • The Inverted File Model (IVF).
  • Class 8 (11/10) — Quantization for Lossy Vector Compression (PDF) [Matthijs · Remote via Zoom]

    • Companion Python Notebook: Class_08_runbook_for_students.ipynb.
    • Vector quantization as a topline (directly optimizing the objective).
    • Binary quantization and Hamming distance comparison.
    • Product quantization (PQ), chunked vector quantization, and optimized product quantization (OPQ).
    • Additive quantization: extension of product quantization and difficulty in training approximations (Residual Quantization, CQ, TQ, LSQ, etc.).
    • Cost of coarse quantization vs. inverted list scanning.
  • Class 9 (11/17) — Graph-Based Indexes (PDF) [Guest Lecturer: Harsha Vardhan Simhadri]

    • Early works: hierarchical k-means.
    • Neighborhood graphs: how to construct them and Nearest Neighbor Descent (NN-Descent).
    • Greedy search in neighborhood graphs: why local greedy routing is insufficient and the need for long-range jumps.
    • HNSW: a practical hierarchical graph-based index.
    • NSG and DiskANN: evolving a k-NN graph for fast, scalable search.
  • Class 10 (12/1) — Student Project and Paper Presentations [Edo + Nataly]

    • In-class final project presentations and discussions (5 minutes per student).

Class Calendar

Below is the schedule of lectures, notes, and project milestones for Fall 2023.

Class Date Topic Instructor(s) Materials & Milestones
1 9/8 Introduction to Vector Search Matthijs, Edo, Nataly Class 1 Notes (PDF)
2 9/15 Text Embeddings Matthijs Class 2 Notes (PDF)
3 9/22 Image Embeddings Matthijs Class 3 Notes (PDF)
4 9/29 Low Dimensional Vector Search Edo Class 4 Notes (PDF)
5 10/6 Dimensionality Reduction Edo Class 5 Notes (PDF)
— 10/13 No Class: Midterm Examination Week —
— 10/20 No Class: Fall Recess —
6 10/27 Approximate Nearest Neighbor Search Edo Class 6 Notes (PDF)
7 11/3 Clustering Edo Class 7 Notes (PDF)
8 11/10 Quantization for Lossy Vector Compression (Zoom) Matthijs Class 8 Notes (PDF) • Notebook
9 11/17 Graph-Based Indexes Harsha Vardhan Simhadri Class 9 Notes (PDF)
— 11/24 No Class: Thanksgiving Recess — Project proposal due
10 12/1 Student Project and Paper Presentations Edo, Nataly Final project submission & presentation

Project & Grading

Class work centers on a final project graded on two equal components:

  • Project Submission (50%): Written report and/or code artifact depending on the chosen project flavor.

  • In-Class Presentation (50%): 5 minutes per student presented during Class 10 (10 minutes for teams of two; 15 minutes for teams of three).

Project Flavors

  • Theory / Research: Propose a new algorithm for a problem explored in class (or modify an existing one), explain what it achieves, and provide experimental evidence or a proof for its behavior. Expected submission: a formal write-up.

  • Data Science / AI: Create an interesting use case for vector search using Pinecone, explain what data you used, what value your application brings, and what insights you gained. Expected submission: code (e.g., Jupyter Notebooks) and a write-up of your results and insights.

  • Engineering / HPC: Adapt or add to FAISS, explain your improvements, and show experimental results. Expected submission: a branch of FAISS for review along with a short write-up of your suggested improvement and experiments.

Logistics & Timeline

  • Project Instructor: Nataly Brukhim (nbrukhim@princeton.edu).

  • Team Size: Projects can be worked on individually, in teams of two, or at most three students.

  • Expected Effort: Expect to spend a few hours over the semester on the one-page project proposal (aim to get it approved well ahead of the 11/24 deadline) and 3–5 full days on the project itself (on par with preparing for a final exam) ahead of the 12/1 submission and presentation.

Selected Literature

Foundational and contemporary papers in dimensionality reduction, sketching, clustering, quantization, and approximate nearest neighbor search:

Contribute & Open Course Materials

All class materials are intended to be used freely by academics anywhere, students and professors alike. Please contribute in the form of pull requests or by opening issues on GitHub.

On Unix-like systems (e.g., macOS or Linux) with bibtex and pdflatex available, you can build the LaTeX lecture notes directly from source:

git clone https://github.com/edoliberty/long-term-memory-in-ai.git
cd long-term-memory-in-ai
./build.sh

Related Classes