Cards as Vectors
embeddings and cosine similarity
Part of: AI Flashcard Generator
A deck of forty cards in the order they were pasted is hard to study. Cards about the heart are mixed in with cards about the lungs. The next two lessons group related cards together, and to do that your code needs a way to measure how similar two cards are. That measurement comes from embeddings . What an embedding is. An embedding turns a piece of text into a list of numbers, a vector , so that texts with similar meaning end up with vectors pointing in similar directions. A real embedding model (OpenAI, Voyage, Cohere, or a local sentence-transformer) returns hundreds of numbers per text, learned from huge amounts of data. For building and testing the pipeline you can use a much simpler stand-in that has the same shape. A bag-of-words vector fixes a small vocabulary and counts how many times each vocabulary word appears in the text. With the vocabulary ["heart", "blood", "lungs", "air"], the text "The heart pumps blood" becomes [1, 1, 0, 0] and "Lungs take in air" becomes [0, 0, 1, 1]. Different topics end up on different axes. Measuring closeness. Two vectors are compared with cosine similarity , the cosine of the angle between them. It is 1.0 when they point the same way, 0.0 w
Challenge: How Close Are Two Cards