EmbeddingGemma: build semantic search on Android
Learn Android semantic search with EmbeddingGemma, cosine similarity and Top K, plus why a 0.4 threshold rejects a bad match in this demo.
Player not loading? Watch on YouTube
This tutorial builds an on-device semantic search demo on Android with EmbeddingGemma. It isolates retrieval using 15 stored words, without a cloud API, vector database or generated answer. In the speaker's example, a literal search for dessert finds nothing, while semantic search retrieves cakes. Searching for encryption returns pencils despite the dataset having no relevant information.
The code walkthrough explains how text becomes an embedding and how the app compares vectors using cosine similarity. Stored text uses the retrieval document role; user queries use retrieval query. The app prepares document embeddings at startup and keeps them in memory, then creates one query embedding per search. It sorts similarity scores and retains the Top K candidates. Retrieval Top K controls result count, unlike generation Top K, which controls candidate tokens.
The speaker sets a minimum similarity of 0.4 to reject the encryption result, but warns that this value is specific to the demo. A useful threshold depends on the model, data, domain and questions. The lesson also explains why exact codes and version numbers can need lexical search. Hybrid retrieval and evaluation are planned for later episodes, as is splitting real documents into searchable pieces. The demo's single-word items leave that document preparation problem unresolved.