MADlib apply `cosine_similarity` on term frequency I am working on a small topic modelling project and I have stumbled upon the idea of developing it in MADlib and PostgreSQL. 

MADlib provides this term frequency function that converts my documents into, well term frequencies.

Are there any other utility functions that can help me to perform madlib.cosine_similarity or madlib.dot_product
 on the generated term frequencies which is essentially stored as sparse matrices (which is not a supported format for the cosine_similarity function that I needed)?
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.