Vector Databases and Semantic Search

Build semantic search that's fast and measurably right: embeddings, exact and approximate indexes, compression, hybrid ranking, filtering and vector databases.

Intermediate · AI Engineering · about 18 hours · 5 modules · certificate on completion

Taught by Ravi Chandrasekharàn, Björn Sigurdssòn, AI Learning Companions.

About this course

Semantic search finds what people mean rather than the words they typed, and it's the retrieval layer under most AI assistants. This course takes you inside it. You'll embed text with a pretrained model and see why normalised vectors make cosine, inner product and Euclidean distance agree; build exact search in NumPy and keep its answers as ground truth; build an inverted-file index from scratch and tune FAISS IVF and HNSW indexes on recall, latency and memory; and compress vectors with int8, binary and product quantisation, winning accuracy back by re-ranking.

Then you'll make search good and safe to use: evaluate relevance with graded queries, recall@k, MRR and nDCG, and a bootstrap that says whether a gain is real; fuse BM25 with dense retrieval; filter by tenant without losing results; and run it all in PostgreSQL with pgvector, with a clear-eyed comparison of FAISS, pgvector, Qdrant, Weaviate and Milvus. Every lab runs on a laptop and was run end to end, and the checks quote its real output. The course stops at retrieval: Building RAG and Agentic Systems takes it on to generation and agents.

What you'll learn

  • Choose an embedding model and similarity measure for search, and explain why normalised vectors make cosine, inner product and L2 rankings agree
  • Build exact, IVF and HNSW indexes and tune nprobe, M and efSearch against recall@k on held-out queries
  • Compress vectors with scalar, binary and product quantisation, and recover accuracy by re-ranking
  • Fuse BM25 with dense retrieval, tune it on dev queries and report recall@k, MRR and nDCG with a bootstrap interval
  • Filter vector search without losing results, and choose between FAISS, pgvector, Qdrant, Weaviate and Milvus for a workload

Skills you'll gain

Semantic search, Text embeddings, Approximate nearest neighbour search, IVF and HNSW indexes, Product quantisation, Hybrid search with BM25, Filtered vector search, Retrieval evaluation, pgvector

Tools

NumPy, scikit-learn, FAISS, sentence-transformers, PostgreSQL, pgvector, Docker

Before you start

Python and NumPy at the level of Python Foundations for Data Science, and Machine Learning Foundations with Python; Text Representation: From Vectors to Context helps. You need Python 3.10 or later with numpy, pandas, scikit-learn, faiss-cpu and sentence-transformers (one 90 MB model download), and Docker for the last lab.

Modules

  1. Embeddings and similarity for search

    How embedding models turn text into vectors for retrieval, which similarity measure to use, and what exact nearest-neighbour search costs: the ground truth for everything that follows.

    • Embedding models for retrieval (12 min)
    • Similarity measures and normalisation (12 min)
    • Exact nearest-neighbour search and its cost (12 min)
    • Hands-on lab: Exact search, metrics and real embeddings
  2. Approximate nearest neighbours: IVF and HNSW

    Why approximate search, how to measure it against exact search, and how inverted-file indexes and HNSW graphs trade recall for speed and memory.

    • Measuring approximate search (10 min)
    • Inverted-file (IVF) indexes (13 min)
    • HNSW graphs (14 min)
    • Hands-on lab: Build IVF from scratch, then tune FAISS IVF and HNSW
  3. Compressing vectors: scalar, binary and product quantisation

    Fit more vectors into memory with float16, int8 and binary codes and with product quantisation, and win back accuracy with IVF residuals and re-ranking.

    • Memory budgets and scalar quantisation (12 min)
    • Product quantisation (14 min)
    • Re-ranking and choosing a compression scheme (11 min)
    • Hands-on lab: Product quantisation from scratch, and FAISS's compressed indexes
  4. Hybrid search, filtering and evaluation

    Measure relevance with labelled queries, combine BM25 with dense retrieval and tune the fusion without fooling yourself, and filter vector search without losing results.

    • Evaluating relevance with labelled queries (13 min)
    • Hybrid search: fusing BM25 and dense results (14 min)
    • Filtering vector search (13 min)
    • Hands-on lab: Hybrid search with honest evaluation, and filters that keep their results
  5. Vector databases in production

    Choose between a library, a PostgreSQL extension and a dedicated vector database, run vector search inside PostgreSQL with pgvector, and operate an index through updates, model changes and growth.

    • Choosing a vector store (13 min)
    • Vector search in PostgreSQL with pgvector (14 min)
    • Operating a vector index (12 min)
    • Hands-on lab: Vector search in PostgreSQL with pgvector

Project: Build and evaluate a semantic search service

A support organisation wants semantic search over its knowledge base, for staff today and as the retrieval layer of an AI assistant later. Build it on the course's help-centre articles, extended to at least 300 articles of your own writing or from an openly licensed source, or on a document set you're allowed to use, with at least 40 labelled queries split into dev and test. Choose and justify an embedding model. Build exact, IVF or HNSW and one compressed index, and pick a configuration that meets recall@10 of 0.95 against exact search within a memory budget you state. Add BM25 and a fusion tuned on dev queries only. Enforce an audience filter (all staff, managers, IT) so that nobody sees articles they shouldn't, with filtered queries still returning k results. Serve it from FAISS or pgvector, and plan how to re-index when the embedding model changes.

Part of

The products this course names are trademarks of their owners, who haven't made or endorsed it.

Start the course free