There are three steps. First, multiply the two lists number by number and add the results: that is the dot product. Second, find each arrow's length: square every number, add them up, and take the square root. Third, divide the dot product by the two lengths multiplied together.
Take a question [3, 4, 0] and a document [4, 3, 1]. The dot product is 3x4 + 4x3 + 0x1 = 24. The lengths are 5 and about 5.10. The cosine is 24 / (5 x 5.10), about 0.941. Now stretch the document ten times, to [40, 30, 10], without turning it. The dot product becomes 240 and the straight-line distance between the tips jumps from 1.73 to 46.31, but the cosine stays at 0.941.
When every vector has length exactly 1, which is called normalised, the three measures agree. Cosine and dot product become the same number, and the squared distance equals 2 - 2 x cosine, so a higher cosine always means a smaller distance. From a real run: a cosine of 0.741 gave a distance of 0.719, the square root of 2 - 2 x 0.741. Many systems normalise vectors once when they store them and then use the dot product, which skips the division.