Loading…
Glossary term
Finding items whose embeddings are closest to a query's embedding.
Vector search finds the stored items whose embeddings are closest to a query's embedding, usually by cosine similarity or distance. Because comparing every item is slow at scale, indexes like HNSW find approximate neighbors quickly. It matches on meaning, not on exact words.
Brute-force nearest neighbors
import numpy as np
def nearest(query, vectors, k=3):
sims = vectors @ query / (np.linalg.norm(vectors, axis=1) * np.linalg.norm(query))
return np.argsort(sims)[::-1][:k]It is how search can find 'how do I get a refund' when the page says 'returns policy'.