I was trying to build a "related posts" feature for my blog, and I started with PostgreSQL's tsvector. It was easy to set up and worked fine, but the results felt kind of meh. It mostly just matched keywords, so the "related" posts were not necessarily related in meaning.
That pushed me to use semantic similarity using embeddings instead, where each post becomes a vector and similarity is based on meaning instead of just words.
I also did not really want to pay for running a personal blog feature like this, even though I know embedding costs are usually pretty low. So I checked if there was any free option, and it turns out Google actually provides free embedding generation through the Gemini API.
To do that, I went to Google AI Studio to grab a free API key.
At first I thought the key was mainly for calling Gemini LLM models, since that is what the UI focuses on. It is not super obvious that you can use the same key for embeddings as well.
But turns out you can generate embeddings for free with Gemini Embedding 2, arguably one of the most powerful embedding models available right now. The free tier is actually pretty usable for prototyping, with roughly ~1,500 requests per day (RPD) and about ~15 requests per minute (RPM), which is more than enough for a small blog or side project.
The API endpoint is pretty simple too:
POST https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-2:embedContent?key={apiKey}
Docs here if you want the official version: