MADlib apply `cosine_similarity` on term frequency
I may be wrong, but I don't think that Postgres has built-in TF-IDF functionality. I'd be super happy to learn that I'm wrong. Obviously, you can parse and roll your own counts. 

In case you don't already know, there's a package that may be of interest to you called pg_similarity, here's one link:

https://salsa.debian.org/postgresql/pg-similarity

It's got a lot of measures. Many, including cosine similarity, can read data off of an index. The pg_similarity extension doesn't help you with storing or processing your corpus, but at least you get the math in a C function. 

In a rare win for RDS, they've got this extension compiled and available. Otherwise, you need your own compile.

Here's hoping that you get a better informed answer...I'm just poking at the Postgres implementations of some of these tools myself.