Skip to content

Instantly share code, notes, and snippets.

@ryan-blunden
Last active February 10, 2026 02:04
Show Gist options
  • Select an option

  • Save ryan-blunden/720fb1d68d43b54f99c012556f88a8fc to your computer and use it in GitHub Desktop.

Select an option

Save ryan-blunden/720fb1d68d43b54f99c012556f88a8fc to your computer and use it in GitHub Desktop.
vector-search.py with requirements.txt
sentence-transformers
torch
huggingface_hub
from sentence_transformers import SentenceTransformer
print("\nLoading embedding model...")
model = SentenceTransformer("google/embeddinggemma-300m", device="mps")
print("\nGenerating vectors...")
documents = ["cymbals", "guitar"]
vectors = model.encode(documents, prompt_name="document", normalize_embeddings=True)
def search():
query = input("\nEnter a query: ")
query_vector = model.encode([query], prompt_name="query", normalize_embeddings=True)[0]
similarity_scores = (vectors @ query_vector.T).reshape(-1)
for doc, score in zip(documents, similarity_scores):
print(f'\n"{query}" vs "{doc}": {score:.4f}')
while True:
search()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment