This chapter moved the project from matching exact words to matching by meaning.
We used embeddings to represent movie descriptions and search queries as vectors. We then compared those vectors to find the most relevant movies. This added semantic retrieval to the project and moved it closer to the retrieval part of a RAG system.
Semantic search finds results with a similar meaning, even when they do not contain the exact words from the query.
For example, a search for “exciting adventure” could match a description containing “thrilling journey.” This makes semantic search useful for natural-language questions, synonyms, and broader concepts.
Keyword search is still useful for exact titles, names, codes, and technical terms.
An embedding is a vector representation of text. In practice, it is a list of numbers produced by an embedding model.
Text with similar meaning should produce similar vectors. This gives us a way to compare meaning using vector math.
These vectors often have hundreds of dimensions. We cannot easily visualize that many dimensions, but the main idea stays the same: similar text should be close in the model’s vector space.
We used the pre-trained all-MiniLM-L6-v2 model through the sentence-transformers library.
It was a good fit for this project because it is small, fast, runs locally, and provides solid general-purpose results. The chapter also covered how model choice depends on the task. Some models are general-purpose, while others are designed for specific domains or multiple languages.
Documents and queries must be embedded with the same model.
Each embedding model creates its own vector space. A vector from one model cannot be meaningfully compared with a vector from another model. Both sides of the search need to use the same model and its tokenizer.
We practiced vector addition and subtraction to see how vector values can be combined or removed.