Last active
February 10, 2026 02:04
-
-
Save ryan-blunden/720fb1d68d43b54f99c012556f88a8fc to your computer and use it in GitHub Desktop.
vector-search.py with requirements.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sentence-transformers | |
| torch | |
| huggingface_hub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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