Comparing Search Vectors by Similarity

A search system can represent documents and queries as vectors and rank by a specified similarity. The choice of vector and score determines which relationships it sees.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace two simple vectors
  2. Check exact identifiers separately
  3. Compute a small cosine comparison
  4. Define preprocessing and zero-vector behavior

Trace two simple vectors

The nonzero vectors \((1,1)\) and \((2,2)\) have cosine similarity one because their directions agree. The second vector has twice the Euclidean length. See dot products and angles.

Check exact identifiers separately

A similarity system may retrieve related wording without guaranteeing an exact code match. Use an explicit term or title policy where exactness matters.[1]

Compute a small cosine comparison

For query vector \((1,1)\), compare A at \((2,2)\) and B at \((2,0)\). Cosine similarity is one with A because their directions agree. For B it is \(1/\sqrt{2}\), about 0.707. See dot products and angles.

q·A=4, norm product 4 → cosine 1
q·B=2, norm product 2√2 → cosine about .707
Positive scaling of one vector leaves cosine unchanged

Define preprocessing and zero-vector behavior

Different encoders organize signals differently. The zero norm makes cosine undefined. A system can skip the vector comparison for that item and still use lexical evidence if it exists. Test similar wording, unrelated wording and an empty input under the chosen representation.

References

  1. Christopher D. Manning, Prabhakar Raghavan and Hinrich Schütze, Introduction to Information Retrieval ↩