A vector search finds the vectors in a database that are closest to a search vector.
Two vectors are compared by Euclidean distance, dot product or cosine distance.
A website has a large number of products. A person describes a product in text: cold, sweet and delivered quickly. The text is converted into a single vector, the search query, and the database holds thousands or millions of vectors.
- A linear scan. The dot product of the search query with each vector is found, the results are sorted, and the lowest 10 distances give the products to recommend. Netflix does the same with the last 10 movies a person has seen. This brute force scan is slow.
- Ranges, one dimension at a time. A dessert query is asked how sweet it is, then how cold, down to the closest vector. This is the KD tree.
- A sort on one dimension. A binary search finds the vector closest in sweetness. Its distance in sweetness is zero and the remaining distances are very large, which always happens with multiple dimensions.