Skip to content

Instantly share code, notes, and snippets.

@jvrdnd
Created May 26, 2023 18:14
Show Gist options
  • Select an option

  • Save jvrdnd/b5f54b315e086dc54527454bf09a78e6 to your computer and use it in GitHub Desktop.

Select an option

Save jvrdnd/b5f54b315e086dc54527454bf09a78e6 to your computer and use it in GitHub Desktop.
distance = lambda a, b: (a @ b.T) / (np.linalg.norm(a) * np.linalg.norm(b))
norms = distance(index["embeddings"], query_embedding)
top_k = np.argpartition(norms, -k)[-k:]
documents = list(itemgetter(*top_k)(index["documents"]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment