As far as I understood the JavaDoc of VectorStore threshold is a lower bound.

The Postgres store uses the threshold as an upper limit to the distance, though.

In addition, the cosine distance must be inverted, see https://github.com/pgvector/pgvector#distances I suggest fixing the comparison operator and also change the sql statement when using cosine.

Comment From: tzolov

Thanks @michael-simons, I believe you have a point. Though still not very certain about lower bound definition I presume that it means similarity (e.g. they higher threshold the similar) as opposite of distance which I've presumed when implementing the pgvector store. And the negative inner product needs additional care as well.