Lesson 2 of 5 · 2 min
Searching many vectors
Comparing a query with every vector is exact and simple. It is fine for thousands of items.
import numpy as np rng = np.random.default_rng(0) store = rng.normal(size=(5000, 64)) store /= np.linalg.norm(store, axis=1, keepdims=True) query = store[1234] + rng.normal(scale=0.05, size=64) query /= np.linalg.norm(query) scores = store @ query top = np.argsort(scores)[::-1][:3] print(top, scores[top].round(3))
