pgvector (1 blogmarks)

← Blogmarks

Generate embeddings for all my TIL posts

I set up an internal process in the Rails app that powers still to run all of my TIL posts through the AWS Bedrock embeddings API. It used the Titan Text Embeddings V2 model and stored the result of each in this app's PostgreSQL database in an embeddings table using pgvector.

Why

I'm experimenting with ways to surface links to similar posts at the bottom of each TIL page. This seemed like both a fun experiment and what would probably end up being fairly accurate and novel results. Using pgvector, I can do comparisons across embeddings of all the posts to find the ones that are most similar in vector space using cosine similarity. That's computed using the <=> (cosine distance) operator provided by pgvector and subtracting it from 1 to get the similarity.

UI

Here is the prototype interface for comparing TF-IDF with Vector Embedding Similarity. I'm still going through and spot checking results for various posts to see which approach I'm happier with.

image

Cost

It's not quite 2000 posts. I knew it would be cheap, but wasn't exactly sure what it would come out to. Maybe like 10 or 20 cents is what I would have guessed. It was a lot cheaper than that. AWS's billing portal rounded up the cost to $0.01.

image