Module 8, Lecture 8.2 | Retrieval-Augmented Generation (RAG)
Vector search is the most common way to implement RAG, and this lecture places each of its pieces in the pipeline from Lecture 8.1, using a customer support knowledge base as the running example. An embedding model is a separate, smaller model from the LLM: it turns a passage into one vector, trained with contrastive objectives so that similar meanings produce nearby vectors. Retrieval embeds the user's question and finds the closest stored vectors by cosine similarity, a normalized dot product, which is why "I'm locked out of my account" can find an article on password resets that keyword search would miss. Embedding APIs from Voyage AI, OpenAI, and Cohere are cheap, but the choice is sticky: vectors from different models cannot be compared, so switching means re-embedding the corpus. A Python dictionary with a linear scan is enough for a small corpus; vector databases add approximate nearest neighbor indexing such as HNSW, persistence, and metadata filtering, and know nothing about LLMs. Chunking splits documents for granularity and window fit, and library defaults are a sound start. The lecture closes by wiring vector search as a tool in the agent loop, where the model sends a query string and gets back text without ever seeing a vector, and by naming where vector RAG fits and where the retrieval methods of Lecture 8.3 do better.
Read the full lecture narrative
text-embedding-3-small and text-embedding-3-large, shortening vectors with the dimensions parameter, and a worked cosine-similarity search.