The last demo turned each document into a list of word weights. To measure how alike two documents are, we line those weights up and multiply them word by word, then add up the products. That single number is the cosine similarity: 0 if they share nothing, 1 if they point exactly the same way. Pick two documents and watch the number get built out of their words.
Every word both documents use adds weightA × weightB to the score. Largest contributions first:
Words only one document uses contribute nothing: they multiply against a zero on the other side and drop out.