Lesson 3 of 8 · 3 min

Meaning as closeness: semantic search

Vectors are also used to find a document by its meaning, without sharing a single word with the question.

ObjectiveExplain how similarity search works and what sets it apart from keyword search.

What holds for a word holds for a sentence or a paragraph. A model can produce a vector for a whole passage that sums up its meaning. Two passages that discuss the same thing in different words get nearby vectors.

This is the basis of semantic search. A vector is computed in advance for each passage of your documents. When you ask a question, its vector is computed and the closest passages are looked up, usually by cosine similarity, which measures the angle between two vectors.

Less effective

Keyword search: “termination” does not find a contract that talks about “early end of the mandate”.

More effective

Semantic search: the question about termination finds the passage on early ending, because the two meanings are close.

Closeness is about meaning, not the exact words.

Its limits

  • It can return a passage that is close in topic but wrong on the specific point, for example another article of the same contract.
  • Figures, dates and exact references are better found by keywords. Good systems combine the two.
  • Quality depends on how the documents are split into passages.

References

  1. Mikolov, Chen, Corrado et al. (2013). Efficient Estimation of Word Representations in Vector Space. arXiv preprint. arxiv.org/abs/1301.3781
  2. Devlin, Chang, Lee et al. (2019). BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding. NAACL-HLT 2019, p. 4171–4186. doi.org/10.18653/v1/N19-1423